From: alex Date: Sun, 15 Jan 2023 17:27:35 +0000 (+0100) Subject: Simplify variable use, add fact support X-Git-Tag: 20240214-emacs~505 X-Git-Url: https://xn--ix-yja.es/gitweb/?a=commitdiff_plain;h=9aeadbe40350e551c524943c24bd7994af58f381;p=alex.git Simplify variable use, add fact support --- diff --git a/personal_infra/playbooks/apply_puppet.yml b/personal_infra/playbooks/apply_puppet.yml index 0a9068b..781678f 100644 --- a/personal_infra/playbooks/apply_puppet.yml +++ b/personal_infra/playbooks/apply_puppet.yml @@ -23,19 +23,38 @@ content: | version: 5 hierarchy: - - name: ansible - path: vars.json + - name: hostvars + path: hostvars.json data_hash: json_data + - name: this + path: this.json + data_hash: json_data + delegate_to: 127.0.0.1 + - name: dump hostvars + copy: + dest: "{{ local_temp.path }}/data/hostvars.json" + content: "{'hostvars': {{ hostvars }} }" + delegate_to: 127.0.0.1 + - name: dump this + copy: + dest: "{{ local_temp.path }}/data/this.json" + content: "{{ hostvars[inventory_hostname] }}" + delegate_to: 127.0.0.1 + - name: get facts + command: facter -y + register: facter_output + - name: create facts directory in local temp + file: + path: "{{ local_temp.path }}/yaml/facts" + state: directory delegate_to: 127.0.0.1 - - name: dump all vars + - name: dump facts copy: - dest: "{{ local_temp.path }}/data/vars.json" - content: "{{ hostvars }}" + dest: "{{ local_temp.path }}/yaml/facts/{{ inventory_hostname }}.yaml" + content: "--- !ruby/object:Puppet::Node::Facts\nvalues:\n {{ facter_output.stdout | indent(width=2) }}" delegate_to: 127.0.0.1 - name: compile catalogs - command: puppet catalog compile --modulepath={{ inventory_dir }}/puppet/modules --hiera_config={{ local_temp.path }}/hiera.yaml --manifest={{ inventory_dir }}/puppet/site --terminus compiler {{ inventory_hostname }} - environment: - FACTER_ansible_inventory_hostname: "{{ inventory_hostname }}" + command: puppet catalog compile --modulepath={{ inventory_dir }}/puppet/modules --hiera_config={{ local_temp.path }}/hiera.yaml --manifest={{ inventory_dir }}/puppet/site --terminus compiler --vardir {{ local_temp.path }}/ --facts_terminus yaml {{ inventory_hostname }} delegate_to: 127.0.0.1 register: catalog - name: install puppet diff --git a/personal_infra/puppet/modules/dns_dhcp/manifests/init.pp b/personal_infra/puppet/modules/dns_dhcp/manifests/init.pp index c7a3552..358633a 100644 --- a/personal_infra/puppet/modules/dns_dhcp/manifests/init.pp +++ b/personal_infra/puppet/modules/dns_dhcp/manifests/init.pp @@ -1,11 +1,11 @@ class dns_dhcp { - $domain = lookup("'$ansible_inventory_hostname'.network.dns_dhcp.domain") + $domain = lookup("network.dns_dhcp.domain") package {'dnsmasq':} -> file {'/etc/dnsmasq.d/internal': content => epp('dns_dhcp/internal', { - 'dns_dhcp' => lookup("'$ansible_inventory_hostname'.network.dns_dhcp"), + 'dns_dhcp' => lookup("network.dns_dhcp"), }), } ~> diff --git a/personal_infra/puppet/modules/proxmox/manifests/init.pp b/personal_infra/puppet/modules/proxmox/manifests/init.pp index 2136036..0fa82d1 100644 --- a/personal_infra/puppet/modules/proxmox/manifests/init.pp +++ b/personal_infra/puppet/modules/proxmox/manifests/init.pp @@ -1,7 +1,7 @@ class proxmox { file {'/etc/network/interfaces': content => epp('proxmox/interfaces', { - "network" => lookup("'$ansible_inventory_hostname'.network"), + "network" => lookup("network"), }), } ~> diff --git a/personal_infra/puppet/site/00-common.pp b/personal_infra/puppet/site/00-common.pp index c502308..b542eb9 100644 --- a/personal_infra/puppet/site/00-common.pp +++ b/personal_infra/puppet/site/00-common.pp @@ -1,28 +1,28 @@ include automatic_updates -$tinc_hosts = lookup("'$ansible_inventory_hostname'.groups.tinc") -$tinc_other_hosts = $tinc_hosts.filter |$host_name| { $host_name != $ansible_inventory_hostname } +$tinc_hosts = lookup("groups.tinc") +$tinc_other_hosts = $tinc_hosts.filter |$host_name| { $host_name != $facts["networking"]["fqdn"] } $tinc_locations = Hash($tinc_hosts.map |$host_name| { [ - lookup("'$host_name'.network.tinc.location"), + lookup("hostvars.'$host_name'.network.tinc.location"), { - subnet => lookup("'$host_name'.network.self_internal_network"), - address => lookup("'$host_name'.network.public_hostname"), + subnet => lookup("hostvars.'$host_name'.network.self_internal_network"), + address => lookup("hostvars.'$host_name'.network.public_hostname"), } ] }) -$tinc_connect_to = $tinc_other_hosts.map |$host_name| { lookup("'$host_name'.network.tinc.location") } +$tinc_connect_to = $tinc_other_hosts.map |$host_name| { lookup("hostvars.'$host_name'.network.tinc.location") } -$tinc_other_networks = $tinc_other_hosts.map |$host_name| { lookup("'$host_name'.network.self_internal_network") } +$tinc_other_networks = $tinc_other_hosts.map |$host_name| { lookup("hostvars.'$host_name'.network.self_internal_network") } -if 'tinc' in lookup("'$ansible_inventory_hostname'.group_names") { +if 'tinc' in lookup("group_names") { class {'tinc': - tinc_name => lookup("'$ansible_inventory_hostname'.tinc_global.name"), - tinc_location => lookup("'$ansible_inventory_hostname'.network.tinc.location"), + tinc_name => lookup("tinc_global.name"), + tinc_location => lookup("network.tinc.location"), tinc_connect_to => $tinc_connect_to, tinc_locations => $tinc_locations, - tinc_ip => lookup("'$ansible_inventory_hostname'.network.self_internal_ip"), - tinc_netmask => lookup("'$ansible_inventory_hostname'.network.self_internal_netmask"), + tinc_ip => lookup("network.self_internal_ip"), + tinc_netmask => lookup("network.self_internal_netmask"), tinc_other_networks => $tinc_other_networks, } }