Using 'hostnamectl' to set unconfigured hostname on CoreOS (#1600)
This commit is contained in:
parent
9bce364b3c
commit
e6ff8c92a0
1 changed files with 14 additions and 3 deletions
|
@ -21,9 +21,20 @@
|
|||
- name: Gather nodes hostnames
|
||||
setup:
|
||||
gather_subset: '!all'
|
||||
filter: ansible_hostname
|
||||
filter: ansible_*
|
||||
|
||||
- name: Assign inventory name to unconfigured hostnames
|
||||
- name: Assign inventory name to unconfigured hostnames (non-CoreOS)
|
||||
hostname:
|
||||
name: "{{inventory_hostname}}"
|
||||
when: ansible_hostname == 'localhost'
|
||||
when: ansible_os_family not in ['CoreOS', 'Container Linux by CoreOS']
|
||||
|
||||
- name: Assign inventory name to unconfigured hostnames (CoreOS only)
|
||||
command: "hostnamectl set-hostname {{inventory_hostname}}"
|
||||
register: hostname_changed
|
||||
when: ansible_hostname == 'localhost' and ansible_os_family in ['CoreOS', 'Container Linux by CoreOS']
|
||||
|
||||
- name: Update hostname fact (CoreOS only)
|
||||
setup:
|
||||
gather_subset: '!all'
|
||||
filter: ansible_hostname
|
||||
when: ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] and hostname_changed.changed
|
||||
|
|
Loading…
Reference in a new issue