summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-inventory/tasks/main.yml
blob: 84ac2c3cf5b20f61fc2191ddc77addab21a12fc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
- name: "No command supplied"
  command: ansible-inventory
  ignore_errors: true
  register: result

- assert:
    that:
        - result is failed
        - '"ERROR! No action selected, at least one of --host, --graph or --list needs to be specified." in result.stderr'

- name: "test option: --list --export"
  command: ansible-inventory --list --export
  register: result

- assert:
    that:
        - result is succeeded

- name: "test option: --list --yaml --export"
  command: ansible-inventory --list --yaml --export
  register: result

- assert:
    that:
        - result is succeeded

- name: "test option: --list --output"
  command: ansible-inventory --list --output junk.txt
  register: result

- name: stat output file
  stat:
      path: junk.txt
  register: st

- assert:
    that:
        - result is succeeded
        - st.stat.exists

- name: "test option: --graph"
  command: ansible-inventory --graph
  register: result

- assert:
    that:
        - result is succeeded

- name: "test option: --graph --vars"
  command: ansible-inventory --graph --vars
  register: result

- assert:
    that:
        - result is succeeded

- name: "test option: --graph with bad pattern"
  command: ansible-inventory --graph invalid
  ignore_errors: true
  register: result

- assert:
    that:
        - result is failed
        - '"ERROR! Pattern must be valid group name when using --graph" in result.stderr'

- name: "test option: --host localhost"
  command: ansible-inventory --host localhost
  register: result

- assert:
    that:
        - result is succeeded

- name: "test option: --host with invalid host"
  command: ansible-inventory --host invalid
  ignore_errors: true
  register: result

- assert:
    that:
        - result is failed
        - '"ERROR! Could not match supplied host pattern, ignoring: invalid" in result.stderr'

- name: "test json output with unicode characters"
  command: ansible-inventory --list -i {{ role_path }}/files/unicode.yml
  register: result

- assert:
    that:
        - result is succeeded
        - result.stdout is contains('příbor')

- block:
  - name: "test json output file with unicode characters"
    command: ansible-inventory --list --output unicode_inventory.json -i {{ role_path }}/files/unicode.yml

  - set_fact:
      json_inventory_file: "{{ lookup('file', 'unicode_inventory.json') }}"

  - assert:
      that:
          - json_inventory_file|string is contains('příbor')
  always:
    - file:
        name: unicode_inventory.json
        state: absent

- name: "test yaml output with unicode characters"
  command: ansible-inventory --list --yaml -i {{ role_path }}/files/unicode.yml
  register: result

- assert:
    that:
        - result is succeeded
        - result.stdout is contains('příbor')

- block:
  - name: "test yaml output file with unicode characters"
    command: ansible-inventory --list --yaml --output unicode_inventory.yaml -i {{ role_path }}/files/unicode.yml

  - set_fact:
      yaml_inventory_file: "{{ lookup('file', 'unicode_inventory.yaml') | string }}"

  - assert:
      that:
          - yaml_inventory_file is contains('příbor')
  always:
    - file:
        name: unicode_inventory.yaml
        state: absent

- include_tasks: toml.yml
  loop:
    -
      - toml<0.10.0
    -
      - toml
    -
      - tomli
      - tomli-w
    -
      - tomllib
      - tomli-w
  loop_control:
    loop_var: toml_package
  when: toml_package is not contains 'tomllib' or (toml_package is contains 'tomllib' and ansible_facts.python.version_info >= [3, 11])