aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-01-15 18:27:35 +0100
committeralex <alex@pdp7.net>2023-01-15 18:27:35 +0100
commit9aeadbe40350e551c524943c24bd7994af58f381 (patch)
treedebbe6846f440b4470cf0c13a2a9c91f92ec4981
parentb21a9114b3712dfa40845359ad6f67da1723dd0d (diff)
Simplify variable use, add fact support
-rw-r--r--personal_infra/playbooks/apply_puppet.yml35
-rw-r--r--personal_infra/puppet/modules/dns_dhcp/manifests/init.pp4
-rw-r--r--personal_infra/puppet/modules/proxmox/manifests/init.pp2
-rw-r--r--personal_infra/puppet/site/00-common.pp24
4 files changed, 42 insertions, 23 deletions
diff --git a/personal_infra/playbooks/apply_puppet.yml b/personal_infra/playbooks/apply_puppet.yml
index 0a9068b5..781678f3 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 c7a35520..358633af 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 21360368..0fa82d18 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 c5023081..b542eb9e 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,
}
}