---
- name: Create security group
  os_security_group:
     cloud: "{{ cloud }}"
     name: "{{ secgroup_name }}"
     state: present
     description: Created from Ansible playbook

- name: Create empty ICMP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: icmp
     remote_ip_prefix: 0.0.0.0/0

- name: Create -1 ICMP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: icmp
     port_range_min: -1
     port_range_max: -1
     remote_ip_prefix: 0.0.0.0/0

- name: Create empty TCP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: tcp
     remote_ip_prefix: 0.0.0.0/0

- name: Create empty UDP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: udp
     remote_ip_prefix: 0.0.0.0/0

- name: Create HTTP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: tcp
     port_range_min: 80
     port_range_max: 80
     remote_ip_prefix: 0.0.0.0/0

- name: Create egress rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: present
     protocol: tcp
     port_range_min: 30000
     port_range_max: 30001
     remote_ip_prefix: 0.0.0.0/0
     direction: egress

- name: Delete empty ICMP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: icmp
     remote_ip_prefix: 0.0.0.0/0

- name: Delete -1 ICMP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: icmp
     port_range_min: -1
     port_range_max: -1
     remote_ip_prefix: 0.0.0.0/0

- name: Delete empty TCP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: tcp
     remote_ip_prefix: 0.0.0.0/0

- name: Delete empty UDP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: udp
     remote_ip_prefix: 0.0.0.0/0

- name: Delete HTTP rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: tcp
     port_range_min: 80
     port_range_max: 80
     remote_ip_prefix: 0.0.0.0/0

- name: Delete egress rule
  os_security_group_rule:
     cloud: "{{ cloud }}"
     security_group: "{{ secgroup_name }}"
     state: absent
     protocol: tcp
     port_range_min: 30000
     port_range_max: 30001
     remote_ip_prefix: 0.0.0.0/0
     direction: egress

- name: Delete security group
  os_security_group:
     cloud: "{{ cloud }}"
     name: "{{ secgroup_name }}"
     state: absent
