diff --git a/Vagrantfile b/Vagrantfile index 94b7b25..42042bd 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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| diff --git a/provision.yaml b/provision.yaml index 232ec30..988a2d9 100644 --- a/provision.yaml +++ b/provision.yaml @@ -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