1
0
Fork 0

Use block for become and make possible to use aliases

This commit is contained in:
Daniele Tricoli 2020-11-15 05:16:59 +01:00
parent 4edd0f8171
commit 7942a4d572
2 changed files with 18 additions and 9 deletions

View File

@ -1,2 +1,6 @@
---
desired_hostname: example.org
hostname_become: true
hostname_become_user: root
hostname: "{{ ansible_fqdn }}"
hostname_aliases: []

View File

@ -1,10 +1,15 @@
---
- name: set the desired hostname
hostname:
name: "{{ desired_hostname }}"
- block:
- name: update 127.0.1.1 entry in /etc/hosts
lineinfile:
path: /etc/hosts
regexp: "^127.0.0.1\t"
line: "^127.0.0.1\t {{ desired_hostname }}"
- name: set the hostname
hostname:
name: "{{ hostname }}"
- name: update 127.0.1.1 entry in /etc/hosts
lineinfile:
path: /etc/hosts
regexp: "^127.0.0.1\t"
line: "^127.0.0.1\t {{ hostname }} {{ hostname_aliases | join(' ') }}"
become: "{{ hostname_become }}"
become_user: "{{ hostname_become_user }}"