d3atiq / netplan-networking

An Ansible role for network interface configuration in Ubuntu 18.04
MIT License
7 stars 6 forks source link

DNS not created correctly #1

Open aloonj opened 6 years ago

aloonj commented 6 years ago

I have used this successfully to set an IP & gateway, however, setting the DNS nameservers as per your readme, results in incorrect netplan format.

Correct:

nameservers:
  addresses: [192.168.0.1, 8.8.8.8]
d3atiq commented 6 years ago

Hi aloonj, Would you kindly show me your playbook and the netplan yams file produced by this role? Thanks!

aloonj commented 6 years ago
roles:
  - role: d3atiq.netplan_networking
    interfaces:
    - interface: ens192
      ipv4:
        configured: true
        address: 192.168.0.1/24
        gateway: 192.168.0.254
      dns:
        nameservers:
        - 8.8.8.8
        - 8.8.4.4
 network:
  version: 2
  renderer: networkd
  ethernets:
    ens192:
      addresses:
       - 192.168.0.1/24
      gateway4: 192.168.0.254
      nameservers:
       - 8.8.8.8
       - 8.8.4.4

netplan try Error in network definition //etc/netplan/ens192.yaml line 9 column 8: expected mapping

line 9 nameservers:

aloonj commented 6 years ago

Should it be ..

       dns:
         nameservers:
          - address: 8.8.8.8
      - address: 8.8.4.4
d3atiq commented 6 years ago

Please try the fix I have provided. It should now be ok. Thanks for pointing it out.

aloonj commented 6 years ago

Great.

The DNS lines no longer complain during "netplan try", so config all looks good. However, I notice that the interface does not come up after running the role. Once I do "netplan try" on the target, the nic config tests OK and comes up fine. Previously when I tried your role (but excluded any DNS), the interface was UP on the target automatically after running the role. Has something changed or do I need to add any variable to ensure its up?

d3atiq commented 6 years ago

So, you run your playbook and then do "netplan try" by hand? Tell me more about that. One reason I have seen interfaces not come up before is a disconnected ethernet cable. With that said, I do provide a handler in the role that does the equivalent of "systemctl restart systemd-networkd". I assume that should be enough to apply the changes, but I am not an expert when it comes to netplan. Also, it is new stuff, it might not be so stable as net tools. In any case, let me know if you find any evidence of mistake in the role, will you?

aloonj commented 6 years ago

Yes if I run the playbook the network is configured but down. Manually running "netplan try" says the config is good (after your fix) and nic then comes up fine.

I'm almost certain that previously, when I ran your role but excluded any DNS settings, the nic came up automatically without intervention with your role.

These are VMs and networks always connected.

I'll try again by excluding DNS settings and see the outcome and report back.

On Mon, 6 Aug 2018, 12:54 Douglas Atique, notifications@github.com wrote:

So, you run your playbook and then do "netplan try" by hand? Tell me more about that. One reason I have seen interfaces not come up before is a disconnected ethernet cable. With that said, I do provide a handler in the role that does the equivalent of "systemctl restart systemd-networkd". I assume that should be enough to apply the changes, but I am not an expert when it comes to netplan. Also, it is new stuff, it might not be so stable as net tools. In any case, let me know if you find any evidence of mistake in the role, will you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/d3atiq/netplan-networking/issues/1#issuecomment-410683255, or mute the thread https://github.com/notifications/unsubscribe-auth/Aanxscw4rY7SHpC_UZYUfUrf8TLbhatkks5uOC5_gaJpZM4VvaOw .

aloonj commented 6 years ago

Apologies I was wrong. Even with DNS settings removed, it does not start the interface automatically. running:

systemctl restart systemd-networkd

on the target system does nothing and does not bring up the new netplan interface. I will try and restart the network with a different method.

netplan apply

This seems to bring it up OK.

aloonj commented 6 years ago

Perhaps something like this (taken from another repo)

- name: Configure network interface
  become: true
  template:
    src: iface.j2
    dest: "/etc/netplan/{{ item.interface }}.yaml"
    owner: root
    group: root
    mode: 0644
  with_items: "{{ interfaces }}"
  register:   _netplan_configured

- name: Applying Netplan Configuration
  command: netplan apply
  become:     true
  when:       _netplan_configured['changed']  

Tested above by editing your tasks/main.yml and it worked perfectly. Interface came UP!

d3atiq commented 6 years ago

Hi aloonj,

I take it you have a point there. I have added a task to run "netplan apply" after configuration. However, I would expect my handler that restarts systemd-networkd to make the changes effective immediately as well. I don't understand why that doesn't happen and I will for now charge it to netplan's developing maturity. :-)

Please try my latest changes and let me know how well this works.

Thanks again for helping improve this Ansible role.

aloonj commented 6 years ago

Great, it works! Thanks for sorting both issues. I should have raised a seperate one for restart problem.

Also thanks for the role, I needed a way to configure nics on Ubuntu 18.04 and I do not yet know enough ansible/jinja2/python to attempt one myself.

d3atiq commented 6 years ago

Cool! Glad it's useful. Thanks for helping me test it.