Skip to content

Commit

Permalink
Manually handle static addressing for private interface
Browse files Browse the repository at this point in the history
Vagrant isn't able to properly configure modern Fedora images [1], so
handle network configuration for eth1 in the provisioning playbook.

[1]: hashicorp/vagrant#12762
  • Loading branch information
larsks committed Jun 13, 2023
1 parent 37805e9 commit 0443932
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ Vagrant.configure("2") do |config|
(1..node_count).each do |machine_id|
config.vm.define "node#{machine_id}" do |node|
node.vm.hostname = "node#{machine_id}"

# We disable dhcp here because Vagrant doesn't know
# how to properly configure modern networkmanager based
# systems. We it ourselves in provision.yaml playbook
# instead.
node.vm.network :private_network,
:ip => "10.0.0.#{10 + machine_id}"
:ip => "10.0.0.#{10 + machine_id}",
:libvirt__dhcp_enabled => false

if machine_id == node_count
node.vm.provision :ansible do |ansible|
Expand Down
10 changes: 10 additions & 0 deletions files/private.nmconnection
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Managed by Ansible
[connection]
id=private
type=ethernet
interface-name=eth1
autoconnect=true

[ipv4]
method=manual
address1={{ address }}
36 changes: 36 additions & 0 deletions provision.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
- hosts: all
gather_facts: false
become: true
tags: [network]
tasks:
- name: Read address from ifcfg file
changed_when: false
command: >-
awk -F= '$1 == "IPADDR" {print $2}' /etc/sysconfig/network-scripts/ifcfg-eth1
register: ifcfg

- name: Create private network config
template:
src: files/private.nmconnection
dest: /etc/NetworkManager/system-connections/private.nmconnection
owner: root
mode: 0600
vars:
address: "{{ ifcfg.stdout }}"
notify: restart nm

handlers:
- name: restart nm
listen: restart nm
service:
name: NetworkManager
state: restarted

- name: bring up interface
listen: restart nm
command: nmcli c up private


- hosts: all
gather_facts: true
become: true
tags: [hosts]
tasks:
- debug:
var: ansible_eth1

- name: Remove old entries from /etc/hosts
lineinfile:
path: /etc/hosts
Expand Down

0 comments on commit 0443932

Please sign in to comment.