mirror of
https://gitea.0xace.cc/ansible-galaxy/hosts.git
synced 2024-11-24 23:06:39 +00:00
add hosts role
This commit is contained in:
commit
93bfec95eb
18
README.md
Normal file
18
README.md
Normal 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
1
defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
pin_hosts: "no"
|
7
meta/main.yml
Normal file
7
meta/main.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
galaxy_info:
|
||||
description: Hostname
|
||||
galaxy_tags:
|
||||
- hostname
|
||||
|
||||
dependencies: []
|
16
tasks/main.yaml
Normal file
16
tasks/main.yaml
Normal 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
|
Loading…
Reference in New Issue
Block a user