Debian Codegraph @

test/integration/targets/preflight_encoding/tasks/main.yml

raw
1 - name: find bash
2 shell: command -v bash
3 register: bash
4 ignore_errors: true
5
6 - meta: end_host
7 when: bash is failed
8
9 - name: get available locales
10 command: locale -a
11 register: locale_a
12 ignore_errors: true
13
14 - set_fact:
15 non_utf8: '{{ locale_a.stdout_lines | select("contains", ".") | reject("search", "(?i)(\.UTF-?8$)") | default([None], true) | first }}'
16 has_cutf8: '{{ locale_a.stdout_lines | select("search", "(?i)C.UTF-?8") != [] }}'
17
18 - name: Test successful encodings
19 shell: '{{ item }} ansible --version'
20 args:
21 executable: '{{ bash.stdout_lines|first }}'
22 loop:
23 - LC_ALL={{ utf8 }}
24 - LC_ALL={{ cutf8 }}
25 - LC_ALL= LC_CTYPE={{ utf8 }}
26 - LC_ALL= LC_CTYPE={{ cutf8 }}
27 when: cutf8 not in item or (cutf8 in item and has_cutf8)
28
29 - name: test locales error
30 shell: LC_ALL=ham_sandwich LC_CTYPE={{ utf8 }} ansible --version
31 args:
32 executable: '{{ bash.stdout_lines|first }}'
33 ignore_errors: true
34 register: locales_error
35
36 - assert:
37 that:
38 - locales_error is failed
39 - >-
40 'ERROR: Ansible could not initialize the preferred locale' in locales_error.stderr
41
42 - meta: end_host
43 when: non_utf8 is falsy
44
45 - name: Test unsuccessful encodings
46 shell: '{{ item }} ansible --version'
47 args:
48 executable: '{{ bash.stdout_lines|first }}'
49 loop:
50 - LC_ALL={{ non_utf8 }}
51 - LC_ALL= LC_CTYPE={{ non_utf8 }}
52 ignore_errors: true
53 register: result
54
55 - assert:
56 that:
57 - result is failed
58 - result.results | select('failed') | length == 2
59 - >-
60 'ERROR: Ansible requires the locale encoding to be UTF-8' in result.results[0].stderr
61 - >-
62 'ERROR: Ansible requires the locale encoding to be UTF-8' in result.results[1].stderr