add hosts role

This commit is contained in:
ikerbs 2021-11-02 17:14:48 +03:00
commit 93bfec95eb
No known key found for this signature in database
GPG Key ID: 5B42DA4F69B5974B
4 changed files with 42 additions and 0 deletions

18
README.md Normal file
View File

@ -0,0 +1,18 @@
Add records in format ${ansible_host} ${FQDN} ${short} from inventory to /etc/hosts
Config example:
pin_hosts: yes
Inventory example:
node1.site.local ansible_host=10.2.1.5
node2.site.local ansible_host=10.2.1.6
node3.site.local ansible_host=10.2.1.7
Result /etc/hosts:
10.2.1.5 node1.site.local node1
10.2.1.6 node2.site.local node2
10.2.1.7 node3.site.local node3

1
defaults/main.yaml Normal file
View File

@ -0,0 +1 @@
pin_hosts: "no"

7
meta/main.yml Normal file
View File

@ -0,0 +1,7 @@
---
galaxy_info:
description: Hostname
galaxy_tags:
- hostname
dependencies: []

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