Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - adding some integration tests for collection roles #50

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
---
name: Linters
on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

'on':
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main
- stable-*
tags:
- '*'

jobs:

linters:
uses: ansible-network/github_actions/.github/workflows/tox-linters.yml@main
ansible-lint:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.8']
steps:
- name: Check out code
uses: actions/checkout@v2
- uses: ansible-network/github_actions/.github/actions/checkout_dependency@main

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v2
- name: Run ansible-lint
uses: ansible/ansible-lint-action@main
with:
python-version: ${{ matrix.python_version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Test with tox
run: tox -e linters -vv

ansible-lint:
uses: ansible-network/github_actions/.github/workflows/ansible-lint.yml@main
action_ref: v6.17.2
15 changes: 6 additions & 9 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
name: sanity
name: Sanity
concurrency:
group: ${{ github.head_ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
types:
- opened
- reopened
- labeled
- unlabeled
- synchronize
- closed
branches:
- main
- stable-*
Expand Down Expand Up @@ -75,6 +68,10 @@ jobs:
{
"ansible-version": "devel",
"python-version": "3.8"
},
{
"ansible-version": "devel",
"python-version": "3.9"
}
]
all_green:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Created by https://www.gitignore.io/api/git,linux,pydev,python,windows,pycharm+all,jupyternotebook,vim,webstorm,emacs,dotenv
# Edit at https://www.gitignore.io/?templates=git,linux,pydev,python,windows,pycharm+all,jupyternotebook,vim,webstorm,emacs,dotenv

tests/output
tests/integration/inventory
### dotenv ###
.env

Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/20230803-ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
breaking_changes:
- Rename roles variables using ``role_name_`` as prefix (https://github.com/redhat-cop/cloud.azure_ops/pull/48).
24 changes: 12 additions & 12 deletions playbooks/roles/scale_virtual_machine/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
operation: create
scale_virtual_machine_operation: create

azure_tags:
scale_virtual_machine_tags:
application: python-demo-webapp-for-ansible-cloud-team

azure_region: eastus
scale_virtual_machine_vm_name: "{{ scale_virtual_machine_resource_group }}-vm"

# Networking variables
azure_virtual_network: "{{ azure_resource_group }}-vnet"
azure_subnet: "{{ azure_resource_group }}-subnet"
azure_vnet_address_prefixes_cidr:
scale_virtual_machine_virtual_network: "{{ scale_virtual_machine_resource_group }}-vnet"
scale_virtual_machine_subnet: "{{ scale_virtual_machine_resource_group }}-subnet"
scale_virtual_machine_vnet_address_prefixes_cidr:
- 10.1.0.0/16
azure_subnet_address_prefixes_cidr: 10.1.0.0/24
azure_security_group: "{{ azure_resource_group }}-nsg"
scale_virtual_machine_subnet_address_prefixes_cidr: 10.1.0.0/24
scale_virtual_machine_security_group: "{{ scale_virtual_machine_resource_group }}-nsg"

azure_load_balancer:
name: "{{ azure_resource_group }}-lb"
public_ip_name: "{{ azure_resource_group }}-lb-public-ip"
backend_address_pool: "{{ azure_resource_group }}-vm-pool"
scale_virtual_machine_load_balancer:
name: "{{ scale_virtual_machine_resource_group }}-lb"
public_ip_name: "{{ scale_virtual_machine_resource_group }}-lb-public-ip"
backend_address_pool: "{{ scale_virtual_machine_resource_group }}-vm-pool"
74 changes: 43 additions & 31 deletions playbooks/roles/scale_virtual_machine/tasks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
- name: Create resource group
ansible.builtin.include_role:
name: cloud.azure_ops.azure_manage_resource_group
vars:
azure_manage_resource_group_tags: "{{ scale_virtual_machine_tags }}"
azure_manage_resource_group_operation: create
azure_manage_resource_group_name: "{{ scale_virtual_machine_resource_group }}"
azure_manage_resource_group_region: "{{ scale_virtual_machine_region }}"

# Create a security group to restrict access to my VMs except within the VPC
- name: Create Network security Group
azure.azcollection.azure_rm_securitygroup:
resource_group: "{{ azure_resource_group }}"
name: "{{ azure_security_group }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ scale_virtual_machine_security_group }}"
rules:
- name: SSH
destination_port_range: 22
Expand All @@ -25,15 +30,22 @@
- name: Create the networking stack
ansible.builtin.include_role:
name: cloud.azure_ops.azure_manage_networking_stack
vars:
azure_manage_networking_stack_operation: create
azure_manage_networking_stack_virtual_network: "{{ scale_virtual_machine_virtual_network }}"
azure_manage_networking_stack_subnet: "{{ scale_virtual_machine_subnet }}"
azure_manage_networking_stack_vnet_address_prefixes_cidr: "{{ scale_virtual_machine_vnet_address_prefixes_cidr }}"
azure_manage_networking_stack_subnet_address_prefixes_cidr: "{{ scale_virtual_machine_subnet_address_prefixes_cidr }}"
azure_manage_networking_stack_resource_group: "{{ scale_virtual_machine_resource_group }}"

# Create a public IP address for the load balancer
- name: Create a public ip address for the load balancer
azure.azcollection.azure_rm_publicipaddress:
resource_group: "{{ azure_resource_group }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
allocation_method: static
name: "{{ azure_load_balancer.public_ip_name }}"
name: "{{ scale_virtual_machine_load_balancer.public_ip_name }}"
sku: Basic
domain_name: "{{ azure_load_balancer.domain_name | default(omit) }}"
domain_name: "{{ scale_virtual_machine_load_balancer.domain_name | default(omit) }}"
register: public_ip

- name: Define load balancer ip address
Expand All @@ -43,14 +55,14 @@
# Deploy Load Balancer that provides public internet access to application routing back to app servers
- name: Create load Balancer
azure.azcollection.azure_rm_loadbalancer:
resource_group: "{{ azure_resource_group }}"
name: "{{ azure_load_balancer.name }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ scale_virtual_machine_load_balancer.name }}"
sku: Basic
frontend_ip_configurations:
- name: frontend
public_ip_address: "{{ azure_load_balancer.public_ip_name }}"
public_ip_address: "{{ scale_virtual_machine_load_balancer.public_ip_name }}"
backend_address_pools:
- name: "{{ azure_load_balancer.backend_address_pool }}"
- name: "{{ scale_virtual_machine_load_balancer.backend_address_pool }}"
probes:
- name: ping_server
port: 5000
Expand All @@ -59,7 +71,7 @@
load_balancing_rules:
- name: flask
frontend_ip_configuration: frontend
backend_address_pool: "{{ azure_load_balancer.backend_address_pool }}"
backend_address_pool: "{{ scale_virtual_machine_load_balancer.backend_address_pool }}"
protocol: Tcp
frontend_port: 5000
backend_port: 5000
Expand All @@ -73,30 +85,30 @@
# Create VM Scale Set
- name: Create Virtual machine scale set
azure.azcollection.azure_rm_virtualmachinescaleset:
resource_group: "{{ azure_resource_group }}"
name: "{{ azure_vm_name }}ss"
vm_size: "{{ azure_vm_size }}"
capacity: "{{ azure_number_vm }}"
tier: "{{ azure_vm_size | regex_search('(Standard|Basic)_*', '\\1') | first }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ scale_virtual_machine_vm_name }}ss"
vm_size: "{{ scale_virtual_machine_vm_size }}"
capacity: "{{ scale_virtual_machine_number_vm }}"
tier: "{{ scale_virtual_machine_vm_size | regex_search('(Standard|Basic)_*', '\\1') | first }}"
upgrade_policy: Manual
admin_username: "{{ azure_vm_user }}"
admin_password: "{{ azure_vm_user_password }}"
admin_username: "{{ scale_virtual_machine_vm_user }}"
admin_password: "{{ scale_virtual_machine_vm_user_password }}"
ssh_password_enabled: true
image: "{{ azure_vm_image }}"
os_type: "{{ azure_vm_os | default('Linux') }}"
managed_disk_type: "{{ azure_vm_image_disk_type | default('Standard_LRS') }}"
virtual_network_resource_group: "{{ azure_resource_group }}"
virtual_network_name: "{{ azure_virtual_network }}"
subnet_name: "{{ azure_subnet }}"
image: "{{ scale_virtual_machine_vm_image }}"
os_type: "{{ scale_virtual_machine_vm_os | default('Linux') }}"
managed_disk_type: "{{ scale_virtual_machine_vm_image_disk_type | default('Standard_LRS') }}"
virtual_network_resource_group: "{{ scale_virtual_machine_resource_group }}"
virtual_network_name: "{{ scale_virtual_machine_virtual_network }}"
subnet_name: "{{ scale_virtual_machine_subnet }}"
public_ip_per_vm: false
load_balancer: "{{ azure_load_balancer.name }}"
security_group: "{{ azure_security_group }}"
load_balancer: "{{ scale_virtual_machine_load_balancer.name }}"
security_group: "{{ scale_virtual_machine_security_group }}"
scale_in_policy: Default

- name: Get virtual machine scale set instance info
azure.azcollection.azure_rm_virtualmachinescalesetinstance_info:
resource_group: "{{ azure_resource_group }}"
vmss_name: "{{ azure_vm_name }}ss"
resource_group: "{{ scale_virtual_machine_resource_group }}"
vmss_name: "{{ scale_virtual_machine_vm_name }}ss"
register: result

- name: Init vm instance list
Expand All @@ -117,11 +129,11 @@
- name: Add bastion host to inventory
ansible.builtin.add_host:
hostname: bastion
ansible_ssh_user: "{{ azure_vm_user }}"
ansible_ssh_pass: "{{ azure_vm_user_password }}"
ansible_sudo_pass: "{{ azure_vm_user_password }}"
ansible_ssh_user: "{{ scale_virtual_machine_vm_user }}"
ansible_ssh_pass: "{{ scale_virtual_machine_vm_user_password }}"
ansible_sudo_pass: "{{ scale_virtual_machine_vm_user_password }}"
ansible_host: "{{ bastion_public_ip }}"
ansible_ssh_common_args: -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no
workers: "{{ vm_instances }}"
workers_join: "{{ join_instances | join(',') }}"
azure_resource_group: "{{ azure_resource_group }}"
azure_resource_group: "{{ scale_virtual_machine_resource_group }}"
36 changes: 18 additions & 18 deletions playbooks/roles/scale_virtual_machine/tasks/create_bastion.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Define Bastion facts
ansible.builtin.set_fact:
bastion_public_ip_name: "{{ azure_vm_name }}bastion-ip"
bastion_nic_name: "{{ azure_vm_name }}bastion-nic"
bastion_public_ip_name: "{{ scale_virtual_machine_vm_name }}bastion-ip"
bastion_nic_name: "{{ scale_virtual_machine_vm_name }}bastion-nic"

- name: Create public ip for Bastion VM
azure.azcollection.azure_rm_publicipaddress:
resource_group: "{{ azure_resource_group }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
allocation_method: static
name: "{{ bastion_public_ip_name }}"
sku: Basic
Expand All @@ -18,28 +18,28 @@

- name: Create network interface for Bastion host
azure.azcollection.azure_rm_networkinterface:
resource_group: "{{ azure_resource_group }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ bastion_nic_name }}"
virtual_network: "{{ azure_virtual_network }}"
subnet_name: "{{ azure_subnet }}"
security_group: "{{ azure_security_group }}"
virtual_network: "{{ scale_virtual_machine_virtual_network }}"
subnet_name: "{{ scale_virtual_machine_subnet }}"
security_group: "{{ scale_virtual_machine_security_group }}"
ip_configurations:
- name: public_ip
public_ip_address_name: "{{ bastion_public_ip_name }}"

- name: Create virtual machine
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ azure_resource_group }}"
name: "{{ azure_vm_name }}bastion"
admin_username: "{{ azure_vm_user }}"
admin_password: "{{ azure_vm_user_password }}"
image: "{{ azure_vm_image }}"
vm_size: "{{ azure_bastion_vm_size | default('Standard_DS4_v2') }}"
resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ scale_virtual_machine_vm_name }}bastion"
admin_username: "{{ scale_virtual_machine_vm_user }}"
admin_password: "{{ scale_virtual_machine_vm_user_password }}"
image: "{{ scale_virtual_machine_vm_image }}"
vm_size: "{{ scale_virtual_machine_bastion_vm_size | default('Standard_DS4_v2') }}"
ssh_password_enabled: true
managed_disk_type: "{{ azure_vm_image_disk_type | default('Standard_LRS') }}"
os_type: "{{ azure_vm_os | default('Linux') }}"
virtual_network_name: "{{ azure_virtual_network }}"
subnet_name: "{{ azure_subnet }}"
managed_disk_type: "{{ scale_virtual_machine_vm_image_disk_type | default('Standard_LRS') }}"
os_type: "{{ scale_virtual_machine_vm_os | default('Linux') }}"
virtual_network_name: "{{ scale_virtual_machine_virtual_network }}"
subnet_name: "{{ scale_virtual_machine_subnet }}"
network_interface_names:
- resource_group: "{{ azure_resource_group }}"
- resource_group: "{{ scale_virtual_machine_resource_group }}"
name: "{{ bastion_nic_name }}"
5 changes: 4 additions & 1 deletion playbooks/roles/scale_virtual_machine/tasks/delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
ansible.builtin.include_role:
name: cloud.azure_ops.azure_manage_resource_group
vars:
azure_force_delete_nonempty: true
azure_manage_resource_group_operation: delete
azure_manage_resource_group_name: "{{ scale_virtual_machine_resource_group }}"
azure_manage_resource_group_region: "{{ scale_virtual_machine_region }}"
azure_manage_resource_group_force_delete_nonempty: true
10 changes: 10 additions & 0 deletions playbooks/roles/scale_virtual_machine/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
- name: Check Resource group name
ansible.builtin.fail:
msg: Azure Resource group name must be defined as scale_virtual_machine_resource_group
when: scale_virtual_machine_resource_group is not defined

- name: Check azure region
ansible.builtin.fail:
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"
22 changes: 11 additions & 11 deletions playbooks/vmss_migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
ansible.builtin.import_role:
name: scale_virtual_machine
vars:
azure_resource_group: "{{ destination_resource_group }}"
azure_region: "{{ destination_region }}"
azure_number_vm: "{{ src_vm_info.vmss.0.sku.capacity }}"
azure_vm_image: "{{ src_vm_info.vmss.0.properties.virtualMachineProfile.storageProfile.imageReference }}"
azure_vm_size: "{{ src_vm_info.vmss.0.sku.name }}"
azure_load_balancer:
scale_virtual_machine_resource_group: "{{ destination_resource_group }}"
scale_virtual_machine_region: "{{ destination_region }}"
scale_virtual_machine_number_vm: "{{ src_vm_info.vmss.0.sku.capacity }}"
scale_virtual_machine_vm_image: "{{ src_vm_info.vmss.0.properties.virtualMachineProfile.storageProfile.imageReference }}"
scale_virtual_machine_vm_size: "{{ src_vm_info.vmss.0.sku.name }}"
scale_virtual_machine_load_balancer:
domain_name: "{{ destination_resource_group | replace('_', '-') }}-{{ destination_region | replace('_', '-') }}-webapp1"
name: "{{ source_resource_group }}-lb"
public_ip_name: "{{ source_resource_group }}-lb-public-ipp"
backend_address_pool: "{{ source_resource_group }}-vm-pool"
operation: create
scale_virtual_machine_operation: create
rescue:
- name: Print failed message
ansible.builtin.debug:
Expand All @@ -59,8 +59,8 @@
ansible.builtin.import_role:
name: scale_virtual_machine
vars:
azure_resource_group: "{{ destination_resource_group }}"
operation: delete
scale_virtual_machine_azure_resource_group: "{{ destination_resource_group }}"
scale_virtual_machine_operation: delete

- name: Failed to create application infrastructure
ansible.builtin.fail:
Expand Down Expand Up @@ -180,8 +180,8 @@
ansible.builtin.import_role:
name: scale_virtual_machine
vars:
azure_resource_group: "{{ destination_resource_group }}"
operation: delete
scale_virtual_machine_resource_group: "{{ destination_resource_group }}"
scale_virtual_machine_operation: delete

- name: Failed to connect
ansible.builtin.fail:
Expand Down
Loading
Loading