summaryrefslogtreecommitdiff
path: root/test/integration/targets/hostname/tasks/test_normal.yml
blob: ed5ac735863c78dff08b8114db663b3f0259417d (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
- name: Ensure hostname doesn't confuse NetworkManager
  when: ansible_os_family == 'RedHat'
  block:
    - name: slurp /var/log/messages
      slurp:
        path: /var/log/messages
      become: yes
      register: messages_before

    - assert:
        that:
          - >
            'current hostname was changed outside NetworkManager' not in messages_before.content|b64decode

- name: Run hostname module for real now
  become: 'yes'
  hostname:
    name: crocodile.ansible.test.doesthiswork.net.example.com
  register: hn2

- name: Get hostname
  command: hostname
  register: current_after_hn2

- name: Ensure hostname doesn't confuse NetworkManager
  when: ansible_os_family == 'RedHat'
  block:
    - name: slurp /var/log/messages
      slurp:
        path: /var/log/messages
      become: yes
      register: messages_after

    - assert:
        that:
          - >
            'current hostname was changed outside NetworkManager' not in messages_after.content|b64decode

- name: Run hostname again to ensure it does not change
  become: 'yes'
  hostname:
    name: crocodile.ansible.test.doesthiswork.net.example.com
  register: hn3

- name: Get hostname
  command: hostname
  register: current_after_hn3

- assert:
    that:
      - hn2 is changed
      - hn3 is not changed
      - current_after_hn2.stdout == 'crocodile.ansible.test.doesthiswork.net.example.com'
      - current_after_hn2.stdout == current_after_hn2.stdout