Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - hosts: all
- gather_facts: true
- tasks:
- - name: Change the hostname
- hostname:
- name: "{{ inventory_hostname }}"
- - name: Add the inventory into /etc/hosts
- # Courtesy of rwngallego on Github
- lineinfile:
- dest: /etc/hosts
- regexp: '.*{{ item }}$'
- line: "{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{item}}"
- state: present
- when: hostvars[item]['ansible_facts']['default_ipv4'] is defined
- with_items:
- - "{{ groups['all'] }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement