Created
February 11, 2020 08:17
-
-
Save omersiar/4c63345c2c193f17b05fa4dadc2bb4f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Provision VMs | |
hosts: localhost | |
connection: local | |
gather_facts: no | |
vars: | |
delimiter: '\' | |
domain_username: "{{ lookup('env','VMWARE_USER').split(delimiter)[-1] }}" | |
tasks: | |
- set_fact: | |
dialog_params: "{{ dialog_options | from_json }}" | |
- debug: var=dialog_params | |
- set_fact: | |
ip_addresses: "{{ dialog_params.dialog.dialog_vm_ip_addresses.split(',') }}" | |
vm_names: "{{ dialog_params.dialog.dialog_vm_names.split(',') }}" | |
dns_servers: "{{ dialog_params.dialog.dialog_network_settings.dns_servers.split(',') }}" | |
- debug: msg="Tower job id is {{ tower_job_id }}" | |
- name: Ensure specified VM folder exists | |
vcenter_folder: | |
validate_certs: no | |
datacenter: '{{ dialog_params.dialog.dialog_datacenter }}' | |
folder_name: '{{ dialog_params.dialog.dialog_folder }}' | |
folder_type: vm | |
state: present | |
- name: Ensure a VM folder for the sub service exists | |
vcenter_folder: | |
validate_certs: no | |
datacenter: '{{ dialog_params.dialog.dialog_datacenter }}' | |
folder_name: '{{ dialog_params.dialog.dialog_sub_service | upper }}' | |
parent_folder: '{{ dialog_params.dialog.dialog_tag_service | upper }}' | |
folder_type: vm | |
state: present | |
when: dialog_params.dialog.dialog_sub_service | length > 0 | |
- name: Deploy Virtual Machine from template in content library | |
vmware_content_deploy_template: | |
host: '{{ dialog_params.dialog.dialog_placement_host_name }}' | |
cluster: '{{ dialog_params.dialog.dialog_placement_cluster_id }}' | |
template: '{{ dialog_params.dialog.dialog_vm_template }}' | |
datastore: '{{ dialog_params.dialog.dialog_placement_ds_id }}' | |
folder: '{{ dialog_params.dialog.dialog_folder }}' | |
datacenter: '{{ dialog_params.dialog.dialog_datacenter }}' | |
name: '{{ vm_name }}' | |
validate_certs: False | |
state: present | |
with_items: "{{ vm_names }}" | |
loop_control: | |
loop_var: vm_name | |
index_var: idx | |
register: result | |
- debug: var=result | |
- name: Customize Virtual Machine | |
vmware_guest: | |
validate_certs: no | |
datacenter: '{{ dialog_params.dialog.dialog_datacenter }}' | |
cluster: '{{ dialog_params.dialog.dialog_placement_cluster_id }}' | |
wait_for_customization: yes | |
state: present | |
name: '{{ vm_name }}' | |
networks: | |
- name: '{{ dialog_params.dialog.dialog_network_settings.port_group }}' | |
ip: '{{ ip_addresses[idx] }}' | |
netmask: '{{ dialog_params.dialog.dialog_network_settings.netmask }}' | |
gateway: '{{ dialog_params.dialog.dialog_network_settings.gateway }}' | |
start_connected: True | |
customization: | |
existing_vm: True | |
hostname: '{{ vm_name }}' | |
password: '{{ dialog_params.dialog.dialog_admin_password }}' | |
dns_servers: '{{ dns_servers }}' | |
domain: '{{ dialog_params.dialog.dialog_network_settings.dns_domain }}' | |
joindomain: '{{ dialog_params.dialog.dialog_network_settings.dns_domain }}' | |
domainadmin: '{{ domain_username }}' | |
domainadminpassword: "{{ lookup('env','VMWARE_PASSWORD') }}" | |
with_items: "{{ vm_names }}" | |
loop_control: | |
loop_var: vm_name | |
index_var: idx | |
register: result | |
- debug: var=result | |
- name: Add VM's to dynamic inventory | |
add_host: | |
ansible_connection: winrm | |
ansible_winrm_transport: kerberos | |
hostname: "{{ item }}" | |
ansible_host: "{{ item + '.' + dialog_params.dialog.dialog_network_settings.dns_domain }}" | |
groups: new_vms | |
ansible_user: "{{ domain_username + '@' + dialog_params.dialog.dialog_network_settings.dns_domain|upper }}" | |
ansible_password: "{{ lookup('env','VMWARE_PASSWORD') }}" | |
ansible_port: 5986 | |
ansible_winrm_scheme: https | |
ansible_winrm_server_cert_validation: ignore | |
loop: '{{ vm_names }}' | |
- name: Install package to new_vms playbook | |
hosts: new_vms | |
gather_facts: no | |
vars: | |
delimiter: '\' | |
domain_username: "{{ lookup('env','VMWARE_USER').split(delimiter)[-1] }}" | |
tasks: | |
- name: Install package | |
win_package: | |
ansible_connection: winrm | |
ansible_winrm_transport: kerberos | |
ansible_user: "{{ domain_username + '@' + dialog_params.dialog.dialog_network_settings.dns_domain|upper }}" | |
ansible_password: "{{ lookup('env','VMWARE_PASSWORD') }}" | |
ansible_port: 5986 | |
ansible_winrm_scheme: https | |
ansible_winrm_server_cert_validation: ignore | |
path: C:\sa_agent\opsware-agent-75.0.79005.0-win32-10.0-X64-Windows2016.exe | |
arguments: '--opsw_gw_addr 10.11.218.112:3001 --force_full_hw_reg --force_sw_reg --crypto_dir C:\sa_agent\opsware-agent' | |
state: present | |
product_id: none | |
# ok: [localhost] => { | |
# "myvar": { | |
# "dialog": { | |
# "dialog_additional_disk_1_size": 0, | |
# "dialog_additional_disk_2_size": 0, | |
# "dialog_additional_disk_3_size": 0, | |
# "dialog_additional_disk_4_size": 0, | |
# "dialog_additional_disk_5_size": 0, | |
# "dialog_cpus": 1, | |
# "dialog_description": "test", | |
# "dialog_extra_disks": 0, | |
# "dialog_folder": "ANSIBLE", | |
# "dialog_identifier": "testg", | |
# "dialog_memory": 1024, | |
# "dialog_number_of_vms": 1, | |
# "dialog_placement_cluster_id": 6, | |
# "dialog_placement_ds_id": "34", | |
# "dialog_retention": "2019-12-05", | |
# "dialog_subnet": "network/ZG5zLm5ldHdvcmskMTAuMS4yMS4wLzI0LzA:10.1.21.0/24/default", | |
# "dialog_tag_application_role": "app", | |
# "dialog_tag_customer": "zb", | |
# "dialog_tag_environment": "test", | |
# "dialog_tag_service": "mobil", | |
# "dialog_vm_ip_addresses": "10.1.21.24", | |
# "dialog_vm_names": "TESTGTESTAPP01", | |
# "dialog_vm_prefix": "TESTGTESTAPP", | |
# "dialog_vm_template": "Windows Server 2016 Standard" | |
# } | |
# } | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment