Skip to content

Commit

Permalink
Finish updating the role_prefix
Browse files Browse the repository at this point in the history
The update to move to role_prefix was incomplete.
There was also an issue with the networking_stack that was fixed as
well.
  • Loading branch information
p3ck committed Mar 7, 2024
1 parent cc4ca44 commit cc96e56
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ Once installed, you can reference the cloud.azure_ops collection content by its
ansible.builtin.include_role:
name: cloud.azure_ops.azure_load_balancer_with_public_ip
vars:
operation: create
azure_resource_group: "{{ resource_group }}"
azure_load_balancer:
azure_load_balancer_with_public_ip_operation: create
azure_load_balancer_with_public_ip_azure_resource_group: "{{ resource_group }}"
azure_load_balancer_with_public_ip_load_balancer:
name: "{{ resource_group }}-lb"
```
Expand Down
12 changes: 12 additions & 0 deletions changelogs/fragments/20240307-update_prefixes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bugfixes:
- Update README.md with proper variable names in example
- Update playbooks/roles/scale_virtual_machine/tasks/main.yml to use correct operation variable
- Fix syntax in roles/azure_manage_networking_stack/README.md
- Use correct variables in roles/azure_manage_networking_stack/tasks/create.yml
- Update defaults to correct variable name in roles/azure_manage_resource_group/defaults/main.yml
- Update roles/azure_manage_resource_group/tasks/main.yml to use correct operation variable
- Update roles/azure_manage_security_group/tasks/main.yml to use correct operation variable
- Update roles/azure_virtual_machine_with_public_ip/defaults/main.yml to use correct prefix vars
- Update roles/azure_virtual_machine_with_public_ip/tasks/create.yml to use correct prefix vars
- Update roles/azure_virtual_machine_with_public_ip/tasks/delete.yml to use correct prefix vars
- Update roles/azure_virtual_machine_with_public_ip/tasks/main.yml to use correct prefix vars
4 changes: 2 additions & 2 deletions playbooks/roles/scale_virtual_machine/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
msg: Azure region must be defined as scale_virtual_machine_region
when: scale_virtual_machine_region is not defined

- name: Include operation tasks
ansible.builtin.include_tasks: "{{ operation }}.yml"
- name: Include scale_virtual_machine_operation tasks
ansible.builtin.include_tasks: "{{ scale_virtual_machine_operation }}.yml"
4 changes: 2 additions & 2 deletions roles/azure_manage_networking_stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Example Playbook
azure_manage_networking_stack_vnet_address_prefixes_cidr:
- "10.1.0.0/16"
- "172.100.0.0/16"
azure_manage_networking_stack_subnet_address_prefixes_cidr
azure_manage_networking_stack_subnet_address_prefixes_cidr:
- "172.100.0.0/8"
azure_manage_networking_stack_tags:
tag0: "tag0"
Expand All @@ -59,4 +59,4 @@ See [LICENCE](https://github.com/redhat-cop/cloud.azure_ops/blob/main/LICENSE) t
Author Information
------------------

- Ansible Cloud Content Team
- Ansible Cloud Content Team
22 changes: 11 additions & 11 deletions roles/azure_manage_networking_stack/tasks/create.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Check that resource group exists
azure.azcollection.azure_rm_resourcegroup_info:
name: "{{ azure_resource_group }}"
name: "{{ azure_manage_networking_stack_resource_group }}"
register: result

- name: Create resource group when it does not exists
Expand All @@ -16,16 +16,16 @@

- name: Create azure virtual network
azure.azcollection.azure_rm_virtualnetwork:
location: "{{ azure_region }}"
name: "{{ azure_virtual_network }}"
address_prefixes_cidr: "{{ azure_vnet_address_prefixes_cidr }}"
resource_group: "{{ azure_resource_group }}"
tags: "{{ azure_tags | default(omit) }}"
location: "{{ azure_manage_networking_stack_region }}"
name: "{{ azure_manage_networking_stack_virtual_network }}"
address_prefixes_cidr: "{{ azure_manage_networking_stack_vnet_address_prefixes_cidr }}"
resource_group: "{{ azure_manage_networking_stack_resource_group }}"
tags: "{{ azure_manage_networking_stack_tags | default(omit) }}"

- name: Create azure subnet
azure.azcollection.azure_rm_subnet:
name: "{{ azure_subnet }}"
virtual_network: "{{ azure_virtual_network }}"
address_prefix_cidr: "{{ azure_subnet_address_prefixes_cidr }}"
resource_group: "{{ azure_resource_group }}"
security_group: "{{ azure_security_group | default(omit) }}"
name: "{{ azure_manage_networking_stack_subnet }}"
virtual_network: "{{ azure_manage_networking_stack_virtual_network }}"
address_prefixes_cidr: "{{ azure_manage_networking_stack_subnet_address_prefixes_cidr }}"
resource_group: "{{ azure_manage_networking_stack_resource_group }}"
security_group: "{{ azure_manage_networking_stack_security_group | default(omit) }}"
2 changes: 1 addition & 1 deletion roles/azure_manage_resource_group/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
# defaults file for resource_group
operation: create
azure_manage_resource_group_operation: create
4 changes: 2 additions & 2 deletions roles/azure_manage_resource_group/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Check operation validation
- name: Check azure_manage_resource_group_operation validation
ansible.builtin.fail:
msg: Please provide operation as 'create' or 'delete'
msg: Please provide azure_manage_resource_group_operation as 'create' or 'delete'
when: azure_manage_resource_group_operation not in ['create', 'delete']

- name: Check Resource group name
Expand Down
2 changes: 1 addition & 1 deletion roles/azure_manage_security_group/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Check operation validation
ansible.builtin.fail:
msg: Please provide operation as 'create' or 'delete'
msg: Please provide azure_manage_security_group_operation as 'create' or 'delete'
when: azure_manage_security_group_operation not in ['create', 'delete']

- name: Check resource group name
Expand Down
6 changes: 3 additions & 3 deletions roles/azure_virtual_machine_with_public_ip/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# defaults file for virtual_machine
operation: create
azure_vm: {}
remove_on_absent: all
azure_virtual_machine_with_public_ip_operation: create
azure_virtual_machine_with_public_ip_operation_vm: {}
azure_virtual_machine_with_public_ip_remove_on_absent: all
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
- name: default
primary: true
public_ip_address_name: "{{ vm_name }}"
load_balancer_backend_address_pools: "{{ azure_vm.load_balancer_backend_address_pools | default(omit) }}"
load_balancer_backend_address_pools: "{{ azure_virtual_machine_with_public_ip_vm.load_balancer_backend_address_pools | default(omit) }}"

- name: Tag all autocreated resources for cleanup
ansible.builtin.set_fact:
Expand Down
6 changes: 3 additions & 3 deletions roles/azure_virtual_machine_with_public_ip/tasks/delete.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: Fail on invalid delete option
ansible.builtin.fail:
msg: Invalid value for remove_on_absent. Valid values include 'all', 'all_autocreated', 'network_interfaces', 'virtual_storage', or 'public_ips'
when: remove_on_absent not in ['all', 'all_autocreated', 'network_interfaces', 'virtual_storage', 'public_ips']
msg: Invalid value for azure_virtual_machine_with_public_ip_remove_on_absent. Valid values include 'all', 'all_autocreated', 'network_interfaces', 'virtual_storage', or 'public_ips'
when: azure_virtual_machine_with_public_ip_remove_on_absent not in ['all', 'all_autocreated', 'network_interfaces', 'virtual_storage', 'public_ips']

- name: Fail when resource group doesn't exist
ansible.builtin.fail:
Expand All @@ -13,5 +13,5 @@
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ azure_resource_group }}"
name: "{{ vm_name }}"
remove_on_absent: "{{ remove_on_absent | default(omit) }}"
remove_on_absent: "{{ azure_virtual_machine_with_public_ip_remove_on_absent | default(omit) }}"
state: absent
16 changes: 8 additions & 8 deletions roles/azure_virtual_machine_with_public_ip/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

- name: Ensure vm name is defined
ansible.builtin.fail:
msg: "Missing parameter: key 'name' not found in azure_virtual_machine_with_public_ip_operation_vm"
when: azure_virtual_machine_with_public_ip_operation_vm.name is not defined
msg: "Missing parameter: key 'name' not found in azure_virtual_machine_with_public_ip_vm"
when: azure_virtual_machine_with_public_ip_vm.name is not defined

- name: Replace invalid chars in name
ansible.builtin.set_fact:
vm_name: "{{ azure_virtual_machine_with_public_ip_operation_vm.name | regex_replace('[^a-zA-Z0-9]', '-') }}"
vm_name: "{{ azure_virtual_machine_with_public_ip_vm.name | regex_replace('[^a-zA-Z0-9]', '-') }}"

- name: Get resource group info
azure.azcollection.azure_rm_resourcegroup_info:
Expand All @@ -28,28 +28,28 @@
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
name: "{{ vm_name }}"
started: false
when: operation == 'power_off'
when: azure_virtual_machine_with_public_ip_operation == 'power_off'

- name: Deallocate VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
name: "{{ vm_name }}"
allocated: false
when: operation == 'deallocate'
when: azure_virtual_machine_with_public_ip_operation == 'deallocate'

- name: Power On VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
name: "{{ vm_name }}"
when: operation == 'power_on'
when: azure_virtual_machine_with_public_ip_operation == 'power_on'

- name: Restart VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
name: "{{ vm_name }}"
restarted: true
when: operation == 'restart'
when: azure_virtual_machine_with_public_ip_operation == 'restart'

- name: Create or delete VM
ansible.builtin.include_tasks: "{{ azure_virtual_machine_with_public_ip_operation }}.yml"
when: operation in ['create', 'delete']
when: azure_virtual_machine_with_public_ip_operation in ['create', 'delete']

0 comments on commit cc96e56

Please sign in to comment.