]> xn--ix-yja.es Git - alex.git/commitdiff
Add Proxmox networking
authoralex <alex@pdp7.net>
Sat, 17 Dec 2022 19:57:20 +0000 (20:57 +0100)
committeralex <alex@pdp7.net>
Sat, 17 Dec 2022 19:57:20 +0000 (20:57 +0100)
personal_infra/README.md
personal_infra/playbooks/apply_puppet.yml
personal_infra/puppet/modules/proxmox/manifests/init.pp [new file with mode: 0644]
personal_infra/puppet/modules/proxmox/templates/interfaces.epp [new file with mode: 0644]
personal_infra/puppet/site/h1.pdp7.net.pp

index 9d46689035c7ff78ea4d5ad3295e3c562055f368..0cd32d5ee62749f70a20081b85ca8905ac1571da 100644 (file)
@@ -4,3 +4,30 @@ This is a collection of files I use setting up my personal infrastructure.
 This is a work in progress, as I am redoing a bit how I do configuration management.
 The main source is in a private repo, but I put here as much material as I can make public.
 Inventory, vaults, etc. remain in the private repo.
+
+## Ansible
+
+### Initial setup
+
+Symlink everything in this directory into your root infrastructure directory.
+
+Create an `inventory` file.
+
+Run `./setup_venv` to create a virtual environment.
+
+Create `vault_password` with a vault password.
+
+### Usage
+
+Run `. .venv/bin/activate` to activate the virtual environment.
+
+Run Ansible commands normally.
+
+## Ansible/Puppet integration
+
+I prefer using Ansible for orchestration, and Puppet for configuration management.
+
+`playbooks/apply_puppet.yml` runs Puppet using Ansible.
+The `puppet` directory contains Puppet manifests.
+
+The playbook adds the Ansible inventory to Puppet using Hiera.
index 5267f1ec16e66550173995dd3933cf62cfa47ac2..15ee4ebf6cbd45b25b34cd13063c4a60478def7e 100644 (file)
       unarchive:
         src: "{{ local_temp.path }}/puppet.tar.gz"
         dest: "{{ remote_temp.path }}"
+    - name: dump variables
+      copy:
+        dest: "{{ remote_temp.path }}/vars.json"
+        content: "{{ hostvars }}"
+    - name: create hiera.yaml
+      copy:
+        dest: "{{ remote_temp.path }}/hiera.yaml"
+        content: |
+          version: 5
+          hierarchy:
+            - name: ansible
+              datadir: {{ remote_temp.path }}
+              path: vars.json
+              data_hash: json_data
     - name: run puppet
-      command: puppet apply {{ remote_temp.path }}
+      command: puppet apply {{ remote_temp.path }} --modulepath={{ remote_temp.path }}/puppet/modules --hiera_config={{ remote_temp.path }}/hiera.yaml
+      environment:
+        FACTER_ansible_inventory_hostname: "{{ inventory_hostname }}"
     - name: clean up local temporary directory
       file:
         state: absent
diff --git a/personal_infra/puppet/modules/proxmox/manifests/init.pp b/personal_infra/puppet/modules/proxmox/manifests/init.pp
new file mode 100644 (file)
index 0000000..dd06cdd
--- /dev/null
@@ -0,0 +1,11 @@
+class proxmox {
+  file {'/etc/network/interfaces':
+    content => epp('proxmox/interfaces', {
+      "network" => lookup("'$ansible_inventory_hostname'.network"),
+    }),
+  }
+  ~>
+  exec {'/usr/sbin/ifreload -a':
+    refreshonly => true
+  }
+}
diff --git a/personal_infra/puppet/modules/proxmox/templates/interfaces.epp b/personal_infra/puppet/modules/proxmox/templates/interfaces.epp
new file mode 100644 (file)
index 0000000..e0bfece
--- /dev/null
@@ -0,0 +1,18 @@
+auto lo
+iface lo inet loopback
+
+auto eno1
+iface eno1 inet static
+       address <%= $network['ip'] %>
+       netmask <%= $network['netmask'] %>
+       gateway <%= $network['gateway'] %>
+
+auto vmbr0
+iface vmbr0 inet static
+       address <%= $network['proxmox']['ip'] %>
+       netmask <%= $network['proxmox']['netmask'] %>
+       bridge_ports none
+       bridge_stp off
+       bridge_fd 0
+       post-up echo 1 > /proc/sys/net/ipv4/ip_forward
+       post-up iptables -t nat -A POSTROUTING -s '<%= $network['proxmox']['network'] %>' -o eno1 -j MASQUERADE
index 7ddb4c5fa94320df9d4b8cc5c5027f529a8f0861..3dd937c5fad5657d2087c6fb8f318f0d4462c060 100644 (file)
@@ -1,2 +1,3 @@
 node 'h1.pdp7.net' {
+  class {'proxmox':}
 }