2017-08-12 18:11:28 +00:00
|
|
|
- name: Create domain name
|
|
|
|
set_fact:
|
|
|
|
domain_name: "ansible-{{ resource_group | hash('md5') | truncate(24, True, '') }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2017-08-12 18:11:28 +00:00
|
|
|
|
2017-08-11 23:16:39 +00:00
|
|
|
- name: Remove public ip
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Create public ip
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
allocation_method: Static
|
2017-08-12 18:11:28 +00:00
|
|
|
domain_name: "{{ domain_name }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: on-exit
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
2019-01-11 05:36:50 +00:00
|
|
|
- output.state.public_ip_allocation_method == 'static'
|
2017-08-12 18:11:28 +00:00
|
|
|
- output.state.dns_settings.domain_name_label == domain_name
|
2017-08-11 23:16:39 +00:00
|
|
|
- output.state.tags | length == 2
|
|
|
|
- output.state.tags.testing == 'testing'
|
|
|
|
|
|
|
|
- name: Should be idempotent
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2019-01-11 05:36:50 +00:00
|
|
|
allocation_method: static
|
2017-08-12 18:11:28 +00:00
|
|
|
domain_name: "{{ domain_name }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
|
|
|
- name: Update tags
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2019-01-11 05:36:50 +00:00
|
|
|
allocation_method: static
|
|
|
|
domain_name: "{{ domain_name }}"
|
2018-08-16 03:35:39 +00:00
|
|
|
append_tags: yes
|
2017-08-11 23:16:39 +00:00
|
|
|
tags:
|
|
|
|
delete: never
|
|
|
|
foo: bar
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 3
|
|
|
|
- output.state.tags.delete == 'never'
|
|
|
|
|
|
|
|
- name: Gather facts, filtering by tag
|
|
|
|
azure_rm_publicipaddress_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
tags:
|
|
|
|
- testing
|
|
|
|
- foo:bar
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_publicipaddresses | length == 1
|
|
|
|
|
|
|
|
- name: Purge all tags
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2019-01-11 05:36:50 +00:00
|
|
|
allocation_method: static
|
|
|
|
domain_name: "{{ domain_name }}"
|
2018-08-16 03:35:39 +00:00
|
|
|
append_tags: no
|
2017-08-11 23:16:39 +00:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 0
|
|
|
|
|
|
|
|
- name: Gather facts for a public ip
|
|
|
|
azure_rm_publicipaddress_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2019-01-11 05:36:50 +00:00
|
|
|
register: pip
|
2017-08-11 23:16:39 +00:00
|
|
|
|
|
|
|
- assert:
|
2019-01-11 05:36:50 +00:00
|
|
|
that:
|
|
|
|
- "pip.publicipaddresses | length == 1"
|
|
|
|
- pip.publicipaddresses[0].name == "pip{{ rpfx }}"
|
|
|
|
- pip.publicipaddresses[0].allocation_method == 'static'
|
|
|
|
- pip.publicipaddresses[0].dns_settings.domain_name_label == domain_name
|
2017-08-11 23:16:39 +00:00
|
|
|
|
|
|
|
- name: Gather facts for all public ips
|
|
|
|
azure_rm_publicipaddress_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_publicipaddresses | length > 0
|
|
|
|
|
2017-08-12 08:03:42 +00:00
|
|
|
- name: Remove public ip
|
2017-08-11 23:16:39 +00:00
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
state: absent
|
|
|
|
|
2017-08-12 08:03:42 +00:00
|
|
|
- name: Gather facts for a public ip
|
2017-08-11 23:16:39 +00:00
|
|
|
azure_rm_publicipaddress_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "pip{{ rpfx }}"
|
2017-08-11 23:16:39 +00:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_publicipaddresses | length == 0
|