ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory update_etc_hosts.yml
[master]
10.10.10.2 set_hostname=maas-k8s-master01 ansible_ssh_port=22 ansible_ssh_user=root
[node]
10.10.10.3 set_hostname=maas-k8s-node01 ansible_ssh_port=22 ansible_ssh_user=root
10.10.10.4 set_hostname=maas-k8s-node02 ansible_ssh_port=22 ansible_ssh_user=root
---
- hosts: all
gather_facts: yes
tasks:
- name: Add IP address of all hosts to all hosts
tags:
- hosts
lineinfile:
state=present
dest=/etc/hosts
regexp="^{{ hostvars[item].ansible_default_ipv4.address }}"
line="{{ hostvars[item].ansible_default_ipv4.address }} {{ hostvars[item].ansible_hostname }}"
with_items:
- '{{ groups.master }}'
- '{{ groups.node }}'