Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit cf4d06a

Browse files
committed
Optionally fill /etc/hosts
1 parent 7104c3e commit cf4d06a

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Generates self-signed CA, client and server certificates. Runs locally on contro
55
Notes:
66
- Will not overwrite any files in output cert dir
77
- Will not copy the files to the remote servers if the local files are unchanged
8+
- Will optionally (see `populate_etc_hosts` variable) add to each machine's `/etc/hosts`
9+
a line for each host in the inventory.
810

911

1012
Requirements
@@ -64,6 +66,7 @@ the resulting relevant files are `copy`ed to the remote target machine.
6466
tls_ca_locality: Rome
6567
tls_ca_organization: Example Inc.
6668
tls_ca_organizationalunit: SysAdmins
69+
populate_etc_hosts: yes
6770
```
6871

6972
If you want to tinker, you can use `vagrant` with the provided `Vagrantfile`.

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ tls_server_valid_days: 730
4444
tls_server_key_size: 4096
4545
# Enable Subject Alternate Name (SAN)
4646
tls_server_enable_san: true
47+
48+
# -------------------
49+
# POPULATE /etc/hosts
50+
# -------------------
51+
populate_etc_hosts: false

inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ all:
1616
tls_ca_locality: Rome
1717
tls_ca_organization: Example Inc.
1818
tls_ca_organizationalunit: SysAdmins
19+
populate_etc_hosts: yes

tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
when:
1818
- generate_tls_certs
1919
- generate_server_cert|bool
20+
21+
- name: Populate /etc/hosts with inventory's hosts
22+
include_tasks: populate-etc-hosts.yaml
23+
when: populate_etc_hosts|bool

tasks/populate-etc-hosts.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Add IP address of all hosts to all hosts
3+
become: yes
4+
lineinfile:
5+
dest: /etc/hosts
6+
regexp: '.*{{ item }}$'
7+
line: "{{ hostvars[item].ansible_host }} {{item}}"
8+
state: present
9+
when: hostvars[item].ansible_host is defined
10+
loop: "{{ groups.all }}"

0 commit comments

Comments
 (0)