Skip to content

Commit

Permalink
Fixes #11: Update static networking playbook for Bookworm.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Mar 7, 2024
1 parent d757569 commit 78f6588
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
1 change: 1 addition & 0 deletions example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ drupal_extra_settings_php: ''
# These networking variables are only necessary if using optional static and
# remote networking features in the `tasks/networking` playbooks.
ipv4_subnet_prefix: "10.1.1"
ipv4_gateway: "10.1.1.1"
active_internet_interface: "wlan0"
reverse_tunnel_enable: false
reverse_tunnel_vps_username: my-vps-username
Expand Down
25 changes: 25 additions & 0 deletions tasks/networking/reverse-tunnel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
gather_facts: false
become: true

handlers:
- name: restart dhcpcd
ansible.builtin.service:
name: dhcpcd
state: restarted

- name: restart autossh
ansible.builtin.systemd:
name: autossh
state: restarted
when: reverse_tunnel_enable

vars_files:
- ../../config.yml

Expand Down Expand Up @@ -61,3 +73,16 @@
name: autossh
state: started
enabled: true

- name: Set active Internet gateway interface on control plane.
ansible.builtin.blockinfile:
path: /etc/dhcpcd.conf
marker: "# ANSIBLE MANAGED - Internet routing metric {mark}"
block: |
interface {{ active_internet_interface }}
metric 100
delegate_to: "{{ groups['control_plane'][0] }}"
run_once: true
notify:
- restart dhcpcd
- restart autossh
49 changes: 25 additions & 24 deletions tasks/networking/static-networking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@

handlers:
- name: restart dhcpcd
service:
ansible.builtin.service:
name: dhcpcd
state: restarted

- name: restart autossh
ansible.builtin.systemd:
name: autossh
- name: restart networkmanager
ansible.builtin.service:
name: NetworkManager
state: restarted
when: reverse_tunnel_enable

vars_files:
- ../../config.yml

tasks:
- name: Configure static IP address on each node.
- name: Check if using dhcpcd for networking.
ansible.builtin.stat:
path: /etc/dhcpcd.conf
register: dhcpcd_file_result

- name: Configure static IP address (dhcpcd).
ansible.builtin.blockinfile:
path: /etc/dhcpcd.conf
marker: "# ANSIBLE MANAGED - static ip {mark}"
Expand All @@ -30,27 +34,24 @@
static routers={{ ipv4_subnet_prefix }}.1
static domain_name_servers={{ ipv4_subnet_prefix }}.1
notify: restart dhcpcd
when: dhcpcd_file_result.stat.exists

- name: Configure static IP address (Network Manager).
community.general.nmcli:
conn_name: "Wired connection 1"
ifname: eth0
type: ethernet
ip4: "{{ ipv4_subnet_prefix }}.{{ ip_host_octet }}/24"
gw4: "{{ ipv4_gateway }}"
state: present
notify: restart networkmanager
when: not dhcpcd_file_result.stat.exists

# TODO: This doesn't use hosts as defined in inventory. Convert to template?
- name: Configure hosts file so nodes can see each other by hostname.
ansible.builtin.blockinfile:
path: /etc/hosts
marker: "# ANSIBLE MANAGED - static ip config {mark}"
block: |
{{ ipv4_subnet_prefix }}.1 node1.local node1
{{ ipv4_subnet_prefix }}.2 node2.local node2
{{ ipv4_subnet_prefix }}.3 node3.local node3
{{ ipv4_subnet_prefix }}.4 node4.local node4
- name: Set active Internet gateway interface on control plane.
ansible.builtin.blockinfile:
path: /etc/dhcpcd.conf
marker: "# ANSIBLE MANAGED - Internet routing metric {mark}"
block: |
interface {{ active_internet_interface }}
metric 100
delegate_to: "{{ groups['control_plane'][0] }}"
run_once: true
notify:
- restart dhcpcd
- restart autossh
{% for host in groups['cluster'] %}
{{ ipv4_subnet_prefix }}.{{ hostvars[host].ip_host_octet }} {{ host }} {{ host | regex_replace('\.local', '') }}
{% endfor %}

0 comments on commit 78f6588

Please sign in to comment.