Skip to content

Commit

Permalink
improve(vpc): Add tags param
Browse files Browse the repository at this point in the history
  • Loading branch information
lixue323 committed Nov 8, 2019
1 parent 290dbf5 commit 41c5f45
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/ansible/modules/cloud/alicloud/ali_eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def main():
try:
if eip.remove_tags(tags):
changed = True
module.exit_json(changed=changed, eip=eip.get().read())
except Exception as e:
module.fail_json(msg="{0}".format(e))

Expand Down
1 change: 1 addition & 0 deletions lib/ansible/modules/cloud/alicloud/ali_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def main():
try:
if vpc.remove_tags(tags):
changed = True
module.exit_json(changed=changed, vpc=vpc.get().read())
except Exception as e:
module.fail_json(msg="{0}".format(e))

Expand Down
1 change: 1 addition & 0 deletions lib/ansible/modules/cloud/alicloud/ali_vswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def main():
try:
if vswitch.remove_tags(tags):
changed = True
module.exit_json(changed=changed, vswitch=vswitch.get().read())
except Exception as e:
module.fail_json(msg="{0}".format(e))

Expand Down
20 changes: 20 additions & 0 deletions tests/ali_eip_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
tags:
Test1: "add1"

- name: Get the existing eip
ali_eip_info:
name_prefix: '{{name}}'

- name: Changed. Modify Tags.
ali_eip:
ip_address: "{{ eip.eip.ip_address }}"
Expand All @@ -124,13 +128,29 @@
Test1: "add1"
Test2: "add3"

- name: Get the existing eip
ali_eip_info:
name_prefix: '{{name}}'

- name: Changed. Removing tags.
ali_eip:
ip_address: "{{ eip.eip.ip_address }}"
purge_tags: True
tags:
Test1: "add1"

- name: No Changed. No tags need to be removed.
ali_eip:
ip_address: "{{ eip.eip.ip_address }}"
purge_tags: True
tags:
Test1: "add1"

- name: Get the existing eip
ali_eip_info:
name_prefix: '{{name}}'
register: eips

- name: Changed. Release ips.
ali_eip:
ip_address: "{{ eip.eip.ip_address }}"
Expand Down
55 changes: 38 additions & 17 deletions tests/ali_vpc_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
Test2: "add2"
with_items: '{{vpcs.vpcs}}'

- name: Get the existing vpc
ali_vpc_info:
name_prefix: '{{name}}'

- name: Filter vpc using tags
ali_vpc_info:
tags:
Expand All @@ -64,6 +68,10 @@
Test2: "add3"
with_items: '{{vpcs.vpcs}}'

- name: Get the existing vpc
ali_vpc_info:
name_prefix: '{{name}}'

- name: Changed. Removing tags.
ali_vpc:
cidr_block: '{{ vpc_cidr }}'
Expand All @@ -73,28 +81,41 @@
Test1: "add1"
with_items: '{{vpcs.vpcs}}'

- name: Changed. Modify description.
- name: No Changed. No tags need to be removed.
ali_vpc:
cidr_block: '{{ vpc_cidr }}'
name: '{{ item.vpc_name }}'
description: '{{ vpc_description }}-modified'
with_items: '{{vpcs.vpcs}}'

- name: Not Changed. No any attribute changed.
ali_vpc:
cidr_block: '{{ vpc_cidr }}'
name: '{{ item.vpc_name }}'
description: '{{ vpc_description }}-modified'
purge_tags: True
tags:
Test1: "add1"
with_items: '{{vpcs.vpcs}}'

- name: Get the existing vpc
ali_vpc_info:
name_prefix: '{{name}}'
register: vpcs

- name: Changed. Deleting vpcs
ali_vpc:
cidr_block: '{{ item.cidr_block }}'
name: '{{ item.vpc_name }}'
state: absent
with_items: '{{vpcs.vpcs}}'
#
# - name: Changed. Modify description.
# ali_vpc:
# cidr_block: '{{ vpc_cidr }}'
# name: '{{ item.vpc_name }}'
# description: '{{ vpc_description }}-modified'
# with_items: '{{vpcs.vpcs}}'
#
# - name: Not Changed. No any attribute changed.
# ali_vpc:
# cidr_block: '{{ vpc_cidr }}'
# name: '{{ item.vpc_name }}'
# description: '{{ vpc_description }}-modified'
# with_items: '{{vpcs.vpcs}}'
#
# - name: Get the existing vpc
# ali_vpc_info:
# name_prefix: '{{name}}'
# register: vpcs
#
# - name: Changed. Deleting vpcs
# ali_vpc:
# cidr_block: '{{ item.cidr_block }}'
# name: '{{ item.vpc_name }}'
# state: absent
# with_items: '{{vpcs.vpcs}}'
30 changes: 30 additions & 0 deletions tests/ali_vswitch_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
tags:
Test1: "add1"

- name: Get the existing vswitch
ali_vswitch_info:
name_prefix: '{{ name }}'
filters:
vpc_id: '{{vpc.vpc.id}}'
register: vswitches

- name: Changed. Modify Tags.
ali_vswitch:
vpc_id: '{{ item.vpc_id}}'
Expand All @@ -50,6 +57,13 @@
Test2: "add3"
with_items: '{{vswitches.vswitches}}'

- name: Get the existing vswitch
ali_vswitch_info:
name_prefix: '{{ name }}'
filters:
vpc_id: '{{vpc.vpc.id}}'
register: vswitches

- name: Changed. Removing tags.
ali_vswitch:
vpc_id: '{{ item.vpc_id}}'
Expand All @@ -59,6 +73,22 @@
Test1: "add1"
with_items: '{{vswitches.vswitches}}'

- name: No Changed. No tags need to be removed.
ali_vswitch:
vpc_id: '{{ item.vpc_id}}'
cidr_block: '{{ item.cidr_block}}'
purge_tags: True
tags:
Test1: "add1"
with_items: '{{vswitches.vswitches}}'

- name: Get the existing vswitch
ali_vswitch_info:
name_prefix: '{{ name }}'
filters:
vpc_id: '{{vpc.vpc.id}}'
register: vswitches

- name: Changed. Modify description.
ali_vswitch:
vpc_id: '{{ item.vpc_id}}'
Expand Down
2 changes: 1 addition & 1 deletion tests/group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ availability_zone: cn-beijing-c
name: ansible-testAcc
description: "Test ansible module "
tags: {For: testAcc, Created: Ansible, From: provider/tests}
policy: '{"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": "*"}],"Version": "1"}'
assume_role_policy: '{"Statement": [{"Action": ["*"],"Effect": "Allow","Resource": "*"}],"Version": "1"}'

# create vpc parameters
vpc_cidr: "172.16.0.0/12"
Expand Down
2 changes: 1 addition & 1 deletion tests/roles/instance/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

tags: '{{ tags }}'
ram_role_name: '{{ ram_role_name }}'
policy: '{{ policy }}'
assume_role_policy: '{{ assume_role_policy }}'
when: not instances.instances

- name: Get the existing ECS instances
Expand Down

0 comments on commit 41c5f45

Please sign in to comment.