add hosts role

This commit is contained in:
ikerbs
2021-11-02 17:14:48 +03:00
commit 93bfec95eb
4 changed files with 42 additions and 0 deletions

16
tasks/main.yaml Normal file
View File

@ -0,0 +1,16 @@
---
- block:
- name: add ip address of all hosts to all hosts
lineinfile:
dest: /etc/hosts
regexp: '.*{{ item }} {{ item.split(".")[0] }}$'
line: "{{ hostvars[item].ansible_host }} {{ item }} {{ item.split('.')[0] }}"
state: present
when:
- hostvars[item].ansible_host is defined
- hostvars[item].pin_hosts is defined
with_items: "{{ groups.all }}"
tags:
- hosts
become: true