2020-07-10 03:04:23 +02:00
|
|
|
# Setting the hostname in our test containers doesn't work currently
|
2020-10-26 21:53:06 +01:00
|
|
|
- when: ansible_facts.virtualization_type not in ('docker', 'container', 'containerd')
|
2020-07-10 03:04:23 +02:00
|
|
|
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
|
|
|
|
|
2020-10-27 22:30:54 +01:00
|
|
|
- import_tasks: test_check_mode.yml
|
|
|
|
- import_tasks: test_normal.yml
|
2020-07-10 03:04:23 +02:00
|
|
|
|
|
|
|
- name: Include distribution specific tasks
|
|
|
|
include_tasks:
|
|
|
|
file: "{{ lookup('first_found', files) }}"
|
|
|
|
vars:
|
|
|
|
files:
|
|
|
|
- "{{ ansible_facts.distribution }}.yml"
|
|
|
|
- default.yml
|
2020-10-27 22:30:54 +01:00
|
|
|
|
2020-07-10 03:04:23 +02:00
|
|
|
always:
|
|
|
|
# Reset back to original hostname
|
|
|
|
- name: Move back original file if it existed
|
|
|
|
command: mv -f {{ _hostname_file }}.orig {{ _hostname_file }}
|
2020-10-27 22:30:54 +01:00
|
|
|
when: hn_stat.stat.exists | default(False)
|
2020-07-10 03:04:23 +02:00
|
|
|
|
|
|
|
- name: Delete the file if it never existed
|
|
|
|
file:
|
|
|
|
path: "{{ _hostname_file }}"
|
|
|
|
state: absent
|
2020-10-27 22:30:54 +01:00
|
|
|
when: not hn_stat.stat.exists | default(True)
|
2020-07-10 03:04:23 +02:00
|
|
|
|
2020-10-27 22:30:54 +01:00
|
|
|
- name: Reset back to original hostname
|
|
|
|
hostname:
|
2020-07-10 03:04:23 +02:00
|
|
|
name: "{{ original.stdout }}"
|
|
|
|
register: revert
|
|
|
|
|
2020-10-27 22:30:54 +01:00
|
|
|
- name: Ensure original hostname was reset
|
|
|
|
assert:
|
2020-07-10 03:04:23 +02:00
|
|
|
that:
|
|
|
|
- revert is changed
|