From c309b1da69bf34914e15279ed26d917566a05601 Mon Sep 17 00:00:00 2001 From: dede Date: Sat, 7 Oct 2023 12:38:18 +0200 Subject: [PATCH] add config_locale role -> bump version to 0.1.1 --- README.md | 12 ++++++--- galaxy.yml | 2 +- roles/config_locale/defaults/main.yml | 3 +++ roles/config_locale/tasks/main.yml | 35 +++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 roles/config_locale/defaults/main.yml create mode 100644 roles/config_locale/tasks/main.yml diff --git a/README.md b/README.md index b68c05c..d3116aa 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,15 @@ if you have any questions or suggestions feel free to get in touch with me. ## roles -* **test** - a simple role to test ansible or just this collection +* **test** – a simple role to test ansible or just this collection it will run a debug task printing 'hello world' -* **docker** - a docker install role that can install docker-ce engine in two ways: +* **config_locale** – role to configure system locale and language settings + you should set `system_locale` and `system_language` if you want to deviate from the default: + ``` + system_locale: 'de_DE.UTF-8' + system_language: 'en_US.UTF-8' + ``` +* **docker** – a docker install role that can install docker-ce engine in two ways: 1. from the official docker repository (recommended by docker) 2. from your distribution you can switch to the distribution method by setting `docker_use_dist_repo` to `true` (defaults to `false`). diff --git a/galaxy.yml b/galaxy.yml index 1c8c960..d00da62 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: dede name: common # The version of the collection. Must be compatible with semantic versioning -version: 0.1.0 +version: 0.1.1 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/roles/config_locale/defaults/main.yml b/roles/config_locale/defaults/main.yml new file mode 100644 index 0000000..7127127 --- /dev/null +++ b/roles/config_locale/defaults/main.yml @@ -0,0 +1,3 @@ +--- +system_locale: 'de_DE.UTF-8' +system_language: 'en_US.UTF-8' diff --git a/roles/config_locale/tasks/main.yml b/roles/config_locale/tasks/main.yml new file mode 100644 index 0000000..b1d2c2e --- /dev/null +++ b/roles/config_locale/tasks/main.yml @@ -0,0 +1,35 @@ +--- +# got this from here: +# https://serverfault.com/questions/959026/how-do-i-generate-and-set-the-locale-using-ansible/981742#981742 + +- name: ensure locale files for '{{ system_locale }}' are available + become: true + community.general.locale_gen: + name: "{{ system_locale }}" + state: present + +- name: ensure locale files for '{{ system_language }}' are available + become: true + community.general.locale_gen: + name: "{{ system_language }}" + state: present + +- name: get current locale and language configuration + ansible.builtin.command: localectl status + register: locale_status + changed_when: false + +- name: set facts locale_lang and locale_language + ansible.builtin.set_fact: + locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}" + locale_language: "{{ locale_status.stdout | regex_search('LANGUAGE=([^\n]+)', '\\1') | default([locale_lang], true) | first }}" + +- name: set locale to '{{ system_locale }}' + become: true + ansible.builtin.command: localectl set-locale LANG={{ system_locale }} + changed_when: locale_lang != system_locale + +- name: set language to '{{ system_language }}' + become: true + ansible.builtin.command: localectl set-locale LANGUAGE={{ system_language }} + changed_when: locale_language != system_language