#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
---
- name: disable cloud-init networking
  copy:
    dest: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
    content: 'network: {config: disabled}'
  # We don't apply network config after doing this because it doesn't actually
  # matter. The next config comes after it and overrides it anyway.
  # I just do this to make things cleaner.
- name: remove 50-cloud-init.yaml
  file: path=/etc/netplan/50-cloud-init.yaml state=absent
- name: configure netplan static ip
  copy:
    dest: /etc/netplan/51-static-ip.yaml
    # Note: some syntax highlighters will say the stanza below is yaml
    # It's not. It's a heredoc
    content: |
      network:
        ethernets:
          eth0:
            dhcp4: no
            addresses:
              - {{ static_ip }}
            gateway4: {{ netplan_gateway }}
            nameservers:
              addresses: {{ netplan_addresses }}
  register: netplan
- name: apply netplan
  command: netplan apply
  when: netplan is changed