Debian Codegraph @

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

raw
1 - block:
2 - name: Include distribution specific variables
3 include_vars: "{{ lookup('first_found', params) }}"
4 vars:
5 params:
6 files:
7 - "{{ ansible_facts.distribution }}.yml"
8 - "{{ ansible_facts.os_family }}.yml"
9 - default.yml
10 paths:
11 - "{{ role_path }}/vars"
12
13 - name: Get current hostname
14 command: hostname
15 register: original
16
17 - import_tasks: test_check_mode.yml
18 - import_tasks: test_normal.yml
19
20 - name: Include distribution specific tasks
21 include_tasks:
22 file: "{{ lookup('first_found', files) }}"
23 vars:
24 files:
25 - "{{ ansible_facts.distribution }}.yml"
26 - default.yml
27
28 always:
29 # Reset back to original hostname
30 - name: Move back original file if it existed
31 become: 'yes'
32 command: mv -f {{ _hostname_file }}.orig {{ _hostname_file }}
33 when: hn_stat.stat.exists | default(False)
34
35 - name: Delete the file if it never existed
36 file:
37 path: "{{ _hostname_file }}"
38 state: absent
39 when: not hn_stat.stat.exists | default(True)
40
41 - name: Reset back to original hostname
42 become: 'yes'
43 hostname:
44 name: "{{ original.stdout }}"
45 register: revert
46
47 - name: Ensure original hostname was reset
48 assert:
49 that:
50 - revert is changed