From e0771d212bd591c1b20e131d13dafbcd8f1cf42b Mon Sep 17 00:00:00 2001
From: Simeon Keske <ca-git@noemis.me>
Date: Wed, 25 Mar 2020 22:06:40 +0100
Subject: [PATCH] generate and set locale

---
 defaults/main.yml  |  2 ++
 tasks/locale.yml   | 17 +++++++++++++++++
 tasks/main.yml     |  6 +++---
 tasks/packages.yml |  2 ++
 4 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 tasks/locale.yml

diff --git a/defaults/main.yml b/defaults/main.yml
index d118863..014624f 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -2,3 +2,5 @@
 users:
 - { name: 'user', state: 'present', public_key: '' }
 - { name: 'nouser', state: 'absent', public_key: '' }
+
+system_locale: en_US.UTF-8
diff --git a/tasks/locale.yml b/tasks/locale.yml
new file mode 100644
index 0000000..d053b57
--- /dev/null
+++ b/tasks/locale.yml
@@ -0,0 +1,17 @@
+- name: Ensure localisation files for '{{ system_locale }}' are available
+  locale_gen:
+    name: "{{ system_locale }}"
+    state: present
+
+- name: Get current locale and language configuration
+  command: localectl status
+  register: locale_status
+  changed_when: false
+
+- name: Parse 'LANG' from current locale and language configuration
+  set_fact:
+    locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}"
+
+- name: Configure locale to '{{ system_locale }}'
+  command: localectl set-locale LANG={{ system_locale }}
+  changed_when: locale_lang != system_locale
diff --git a/tasks/main.yml b/tasks/main.yml
index f971192..772dee6 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,7 +1,9 @@
 ---
-  - import_tasks: packages.yml
+  - include: packages.yml
+  - include: locale.yml
   - include: sudo.yml
   - include: molly-guard.yml
+  - include: sshd.yml
 
   - include: user.yml user={{ users }}
     tags: user
@@ -14,5 +16,3 @@
       group: root
       mode: 0644
     when: motd_path is defined
-
-  - include: sshd.yml
diff --git a/tasks/packages.yml b/tasks/packages.yml
index d01dc34..abe2eb2 100644
--- a/tasks/packages.yml
+++ b/tasks/packages.yml
@@ -28,5 +28,7 @@
     - python3-setuptools
     - rsync
     - gnupg
+    - sudo
+    - curl
     state: present
   tags: packages