Advertisement
Guest User

hostname.yaml

a guest
Nov 12th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.51 KB | None | 0 0
  1. - hosts: all  
  2.   gather_facts: true  
  3.  
  4.   tasks:
  5.   - name: Change the hostname
  6.     hostname:
  7.       name: "{{ inventory_hostname }}"  
  8.  
  9.   - name: Add the inventory into /etc/hosts
  10.     # Courtesy of rwngallego on Github
  11.     lineinfile:
  12.       dest: /etc/hosts
  13.       regexp: '.*{{ item }}$'
  14.       line: "{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{item}}"
  15.       state: present
  16.     when: hostvars[item]['ansible_facts']['default_ipv4'] is defined
  17.     with_items:
  18.      - "{{ groups['all'] }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement