Check that locales are already configured.
If not - configure and regenerate.
--- /dev/null
+- name: Configure locales
+ become: true
+ lineinfile:
+ path: /etc/locale.gen
+ regexp: "^{{ item }}"
+ line: "{{ item }}"
+ loop: [
+ 'en_US ISO-8859-1',
+ 'ru_RU.KOI8-R KOI8-R',
+ 'ru_RU.UTF-8 UTF-8',
+ ]
+ notify: Regenerate locales
+
+- name: Regenerate locales
+ become: true
+ command: /usr/sbin/locale-gen
id: 5C808C2B65558117
when: "inventory_hostname in ('localhost', 'iskra-aviel.phdru.name')"
-- name: Configure locales
- become: true
- blockinfile:
- path: /etc/locale.gen
- block: |
- en_US ISO-8859-1
- ru_RU.KOI8-R KOI8-R
- ru_RU.UTF-8 UTF-8
-- name: Regenerate locales
- become: true
- command: /usr/sbin/locale-gen
+- name: Check locales
+ command: grep -c '^ru_RU.KOI8-R' /etc/locale.gen
+ register: has_locales
+- debug:
+ msg: "Creating and regenerating locales..."
+ notify: Configure locales
+ when: has_locales.stdout == "0"