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

Commit 0bcb4b8

Browse files
committed
Optional tld
When updating /etc/hosts to add the hosts in the inventory, also add the name postfixed with a configurable tld.
1 parent f485128 commit 0bcb4b8

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ gen_tls_server_enable_san: true
5050
# POPULATE /etc/hosts
5151
# -------------------
5252
gen_tls_populate_etc_hosts: false
53+
# gen_tls_tld:

inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ all:
1717
gen_tls_ca_organization: Example Inc.
1818
gen_tls_ca_organizationalunit: SysAdmins
1919
gen_tls_populate_etc_hosts: yes
20+
gen_tls_tld: example

tasks/generate-server-cert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
path: "{{ gen_tls_cert_dir }}/{{ inventory_hostname_short }}.csr"
5959
privatekey_path: "{{ gen_tls_cert_dir }}/{{ inventory_hostname_short }}.key"
6060
common_name: "{{inventory_hostname_short}}"
61-
subject_alt_name: "DNS:{{inventory_hostname}},DNS:{{inventory_hostname_short}},IP:{{(alt_interface_ip is defined) | ternary(alt_interface_ip, ansible_default_ipv4.address)}},IP:0.0.0.0,IP:127.0.0.1"
61+
subject_alt_name: "{% if gen_tls_tld is defined %}DNS:{{ inventory_hostname_short }}.{{ gen_tls_tld }},{% endif %}DNS:{{inventory_hostname}},DNS:{{inventory_hostname_short}},IP:{{(alt_interface_ip is defined) | ternary(alt_interface_ip, ansible_default_ipv4.address)}},IP:0.0.0.0,IP:127.0.0.1"
6262
when:
6363
- not server_csr.stat.exists
6464
- gen_tls_generate_server_cert

tasks/populate-etc-hosts.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
lineinfile:
55
dest: /etc/hosts
66
regexp: '.*{{ item }}$'
7-
line: "{{ hostvars[item].ansible_host }} {{item}}"
7+
line: "{{ hostvars[item].ansible_host }} {{item}}{% if gen_tls_tld is defined %} {{ item }}.{{ gen_tls_tld }}{% endif %}"
88
state: present
99
when: hostvars[item].ansible_host is defined
1010
loop: "{{ groups.all }}"

0 commit comments

Comments
 (0)