This repository has been archived on 2020-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
ansible.basics/tasks/main.yml

36 lines
982 B
YAML
Raw Normal View History

---
# tasks file for basics
## Modify /etc/hosts
- name: Set 127.0.0.1 line in hosts file
lineinfile:
dest: /etc/hosts
state: present
regexp: "^{{ ansible_lo.ipv4.address }}"
line: "{{ ansible_lo.ipv4.address }} {{ basics__hosts_localhost_content }}"
backup: yes
when: (basics__hosts_localhost_manage and
ansible_lo.ipv4.address is defined)
- name: Set ipv4 line in hosts file
lineinfile:
dest: /etc/hosts
state: present
regexp: "^{{ ansible_default_ipv4.address }}"
line: "{{ ansible_default_ipv4.address }} {{ basics__hosts_ipv4_content }}"
backup: yes
when: (basics__hosts_ipv4_manage and
ansible_default_ipv4.address is defined)
register: basics__register_ipv4_line
- name: Purge other lines with hostname
lineinfile:
dest: /etc/hosts
state: absent
regexp: '^(?!({{ ansible_default_ipv4.address }})).*{{ ansible_hostname }}'
backup: yes
when: basics__register_ipv4_line.changed
## }}}