From 9b7ab0915eae32f00925b104c6838e6625d639fb Mon Sep 17 00:00:00 2001 From: willtome Date: Thu, 9 Jun 2022 13:45:47 -0400 Subject: [PATCH] add azure --- cloud/blueprints/windows.yml | 10 ++++++- cloud/destroy_vm.yml | 2 +- cloud/setup.yml | 19 +++++++++++++ .../demo/cloud/roles/azure/defaults/main.yml | 12 ++++++-- .../cloud/roles/azure/tasks/create_infra.yml | 4 +-- .../cloud/roles/azure/tasks/create_vm.yml | 28 +++++++++++++++++++ .../cloud/roles/azure/tasks/destroy_vm.yml | 8 ++++++ 7 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 collections/ansible_collections/demo/cloud/roles/azure/tasks/destroy_vm.yml diff --git a/cloud/blueprints/windows.yml b/cloud/blueprints/windows.yml index 2c000f5..d70ca69 100644 --- a/cloud/blueprints/windows.yml +++ b/cloud/blueprints/windows.yml @@ -1,6 +1,14 @@ --- vm_blueprint_providers: - aws + - azure aws_image_filter: 'Windows_Server-2019-English-Core-Base*' aws_instance_size: t3.medium -aws_userdata_template: aws_windows_userdata \ No newline at end of file +aws_userdata_template: aws_windows_userdata +az_vm_os_type: Windows +az_vm_size: Standard_DS1_v2 +az_vm_image: + offer: WindowsServer + publisher: MicrosoftWindowsServer + sku: 2022-Datacenter + version: latest \ No newline at end of file diff --git a/cloud/destroy_vm.yml b/cloud/destroy_vm.yml index 183b221..0d68921 100644 --- a/cloud/destroy_vm.yml +++ b/cloud/destroy_vm.yml @@ -12,4 +12,4 @@ include_role: name: "demo.cloud.aws" tasks_from: destroy_vm - when: "'cloud_aws' in group_names" \ No newline at end of file + when: "'cloud_aws' in group_names or 'cloud_azure' in group_names" \ No newline at end of file diff --git a/cloud/setup.yml b/cloud/setup.yml index 1d80515..94bec51 100644 --- a/cloud/setup.yml +++ b/cloud/setup.yml @@ -35,6 +35,23 @@ controller_inventory_sources: - key: platform prefix: os + - name: Azure Inventory + organization: Default + source: azure_rm + inventory: Workshop Inventory + credential: Azure + overwrite: true + source_vars: + hostnames: + - tags.Name + - default + keyed_groups: + - key: os_profile.system + prefix: os + groups: + cloud_azure: true + + controller_templates: - name: Cloud / Create Infra job_type: run @@ -58,6 +75,7 @@ controller_templates: required: true choices: - aws + - azure - question_name: AWS Public Key (only required for aws provider) type: textarea required: false @@ -93,6 +111,7 @@ controller_templates: required: true choices: - aws + - azure - question_name: Blueprint type: multiplechoice variable: vm_blueprint diff --git a/collections/ansible_collections/demo/cloud/roles/azure/defaults/main.yml b/collections/ansible_collections/demo/cloud/roles/azure/defaults/main.yml index e38e0e3..085623d 100644 --- a/collections/ansible_collections/demo/cloud/roles/azure/defaults/main.yml +++ b/collections/ansible_collections/demo/cloud/roles/azure/defaults/main.yml @@ -2,8 +2,16 @@ ############## # Azure Vars ############## -az_region: +az_region: eastus az_rg_name: ansible az_rg_prefix: demo az_vnet_cidr_block: 10.0.0.0/16 -az_subnet_cidr: 10.0.1.0/24 \ No newline at end of file +az_subnet_cidr: 10.0.1.0/24 +az_vm_name: "{{ vm_name }}" +az_vm_owner: "{{ vm_owner }}" +az_blueprint: "{{ vm_blueprint }}" +az_vm_username: "{{ ansible_user }}" +az_vm_password: "{{ ansible_password }}" +az_env_tag: prod +az_purpose_tag: ansible_demo +az_ansiblegroup_tag: cloud diff --git a/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_infra.yml b/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_infra.yml index cc655e3..c7f5804 100644 --- a/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_infra.yml +++ b/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_infra.yml @@ -1,8 +1,8 @@ --- - name: AZURE | CREATE INFRA | resource group azure.azcollection.azure_rm_resourcegroup: - name: "{{ az_rg_name }}-{{ az_rg_prefix }}-rg" - location: "{{ az_region }}" + name: "{{ az_rg_name }}-{{ az_rg_prefix }}-rg" + location: "{{ az_region }}" - name: AZURE | CREATE INFRA | virtual network azure.azcollection.azure_rm_virtualnetwork: diff --git a/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_vm.yml b/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_vm.yml index e69de29..560bdc2 100644 --- a/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_vm.yml +++ b/collections/ansible_collections/demo/cloud/roles/azure/tasks/create_vm.yml @@ -0,0 +1,28 @@ +--- +- name: AZURE | CREATE VM | vnet interface + azure.azcollection.azure_rm_networkinterface: + resource_group: "{{ az_rg_name }}-{{ az_rg_prefix }}-rg" + name: "{{ az_vm_name }}_nic" + public_ip_name: "{{ az_vm_name }}_ip" + virtual_network: "{{ az_rg_name }}-{{ az_rg_prefix }}-vnet" + subnet: "{{ az_rg_name }}-{{ az_rg_prefix }}-subnet }}" + security_group: "{{ az_rg_name }}-{{ az_rg_prefix }}-sec-group" + +- name: AZURE | CREATE VM | vm + azure.azcollection.azure_rm_virtualmachine: + resource_group: "{{ az_rg_name }}-{{ az_rg_prefix }}-rg" + name: "{{ az_vm_name }}" + os_type: "{{ az_vm_os_type }}" + vm_size: "{{ az_vm_size }}" + admin_username: "{{ az_vm_username }}" + admin_password: "{{ az_vm_password }}" + network_interfaces: "{{ az_vm_name }}_nic" + image: "{{ az_vm_image }}" + tags: + blueprint: "{{ az_blueprint }}" + purpose: "{{ az_purpose_tag }}" + env: "{{ az_env_tag }}" + ansible_group: "{{ az_ansiblegroup_tag }}" + owner: "{{ az_vm_owner }}" + info: "This instance was built by Red Hat Product Demos" + Name: "{{ az_vm_name }}" diff --git a/collections/ansible_collections/demo/cloud/roles/azure/tasks/destroy_vm.yml b/collections/ansible_collections/demo/cloud/roles/azure/tasks/destroy_vm.yml new file mode 100644 index 0000000..9be4644 --- /dev/null +++ b/collections/ansible_collections/demo/cloud/roles/azure/tasks/destroy_vm.yml @@ -0,0 +1,8 @@ +--- +- name: Destroy VM + azure.azcollection.azure_rm_virtualmachine: + resource_group: "{{ az_rg_name }}-{{ az_rg_prefix }}-rg" + name: "{{ inventory_hostname }}" + state: absent + remove_on_absent: all_autocreated + delegate_to: localhost \ No newline at end of file