diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/hostname/tasks/main.yml | |
parent | Initial commit. (diff) | |
download | ansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/hostname/tasks/main.yml')
-rw-r--r-- | test/integration/targets/hostname/tasks/main.yml | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/integration/targets/hostname/tasks/main.yml b/test/integration/targets/hostname/tasks/main.yml new file mode 100644 index 0000000..596dd89 --- /dev/null +++ b/test/integration/targets/hostname/tasks/main.yml @@ -0,0 +1,52 @@ +# Setting the hostname in our test containers doesn't work currently +- when: ansible_facts.virtualization_type not in ('docker', 'container', 'containerd') + block: + - name: Include distribution specific variables + include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts.distribution }}.yml" + - "{{ ansible_facts.os_family }}.yml" + - default.yml + paths: + - "{{ role_path }}/vars" + + - name: Get current hostname + command: hostname + register: original + + - import_tasks: test_check_mode.yml + - import_tasks: test_normal.yml + + - name: Include distribution specific tasks + include_tasks: + file: "{{ lookup('first_found', files) }}" + vars: + files: + - "{{ ansible_facts.distribution }}.yml" + - default.yml + + always: + # Reset back to original hostname + - name: Move back original file if it existed + become: 'yes' + command: mv -f {{ _hostname_file }}.orig {{ _hostname_file }} + when: hn_stat.stat.exists | default(False) + + - name: Delete the file if it never existed + file: + path: "{{ _hostname_file }}" + state: absent + when: not hn_stat.stat.exists | default(True) + + - name: Reset back to original hostname + become: 'yes' + hostname: + name: "{{ original.stdout }}" + register: revert + + - name: Ensure original hostname was reset + assert: + that: + - revert is changed |