From dce5b257025c4da1bb43f5b4e3c3842fa85687f0 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 23 Aug 2023 17:54:55 -0400 Subject: [PATCH] autogenerate hosts --- roles/firewall/defaults/main.yml | 2 -- roles/firewall/tasks/main.yml | 2 +- roles/networking/hosts/tasks/main.yml | 6 ++++++ roles/networking/hosts/templates/hosts.j2 | 9 +++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 roles/networking/hosts/tasks/main.yml create mode 100644 roles/networking/hosts/templates/hosts.j2 diff --git a/roles/firewall/defaults/main.yml b/roles/firewall/defaults/main.yml index ef4d9d2..267b80d 100644 --- a/roles/firewall/defaults/main.yml +++ b/roles/firewall/defaults/main.yml @@ -4,7 +4,5 @@ # LAN static IP address local_subnet: 192.168.0.0/24 -# local IP of bastion node -bastion_ip: null sshd_port: 2500 diff --git a/roles/firewall/tasks/main.yml b/roles/firewall/tasks/main.yml index 6595509..a65bb56 100644 --- a/roles/firewall/tasks/main.yml +++ b/roles/firewall/tasks/main.yml @@ -14,7 +14,7 @@ - name: Set default sources (fleet server) set_fact: - default_firewall_src: "{{ bastion_ip }}" + default_firewall_src: "{{ host_vars[groups['bastion'][0]]['local_ip'] }}" when: "fleet" in group_names - name: Allow service ports diff --git a/roles/networking/hosts/tasks/main.yml b/roles/networking/hosts/tasks/main.yml new file mode 100644 index 0000000..5cf0d02 --- /dev/null +++ b/roles/networking/hosts/tasks/main.yml @@ -0,0 +1,6 @@ +--- + +- name: Deploy /etc/hosts template + template: + src: hosts.j2 + dest: /etc/hosts diff --git a/roles/networking/hosts/templates/hosts.j2 b/roles/networking/hosts/templates/hosts.j2 new file mode 100644 index 0000000..bb266cd --- /dev/null +++ b/roles/networking/hosts/templates/hosts.j2 @@ -0,0 +1,9 @@ +# Static table lookup for hostnames. +# See hosts(5) for details. + +# This file (/etc/hosts) is automatically generated via Ansible. +# Modifications will be lost! + +{% for host in groups["all"] %} +{{ host_vars[host]["local_ip"] }} {{ host }} +{% endfor %}