---
- name: Create network {{ network_name }}
  os_network:
    cloud: "{{ cloud }}"
    name: "{{ network_name }}"
    state: present

- name: Create subnet {{ subnet_name }} on network {{ network_name }}
  os_subnet:
    cloud: "{{ cloud }}"
    network_name: "{{ network_name }}"
    name: "{{ subnet_name }}"
    state: present
    enable_dhcp: "{{ enable_subnet_dhcp }}"
    dns_nameservers:
      - 8.8.8.7
      - 8.8.8.8
    cidr: 192.168.0.0/24
    gateway_ip: 192.168.0.1
    allocation_pool_start: 192.168.0.2
    allocation_pool_end: 192.168.0.254

- name: Update subnet
  os_subnet:
    cloud: "{{ cloud }}"
    network_name: "{{ network_name }}"
    name: "{{ subnet_name }}"
    state: present
    dns_nameservers:
      - 8.8.8.7
    cidr: 192.168.0.0/24

- name: Delete subnet {{ subnet_name }}
  os_subnet:
    cloud: "{{ cloud }}"
    name: "{{ subnet_name }}"
    state: absent

- name: Delete network {{ network_name }}
  os_network:
    cloud: "{{ cloud }}"
    name: "{{ network_name }}"
    state: absent
