Created
April 6, 2018 02:30
-
-
Save mrlesmithjr/3203c04299b40ae5f07dac70f3c20bc6 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
--- | |
- hosts: localhost | |
gather_facts: false | |
become: false | |
# vars: | |
# ansible_python_interpreter: /usr/local/bin/python2 | |
tasks: | |
- name: Managing VMs | |
vmware_guest: | |
annotation: Ansible Provisioned | |
cluster: "{{ vcenter_cluster }}" | |
customization: "{{ item['customization']|default(omit) }}" | |
datacenter: "{{ vcenter_datacenter }}" | |
disk: "{{ item['disks']|default(omit) }}" | |
folder: "/{{ vcenter_datacenter }}/vm" | |
force: true | |
guest_id: "{{ item['guest_id'] }}" | |
hardware: "{{ item['vm_hardware']|default(omit) }}" | |
hostname: "{{ vcenter_host }}" | |
name: "{{ item['name'] }}" | |
networks: "{{ item['networks']|default(omit) }}" | |
password: "{{ vcenter_password }}" | |
template: "{{ item['template']|default(omit) }}" | |
username: "{{ vcenter_username }}" | |
state: "{{ item['state'] }}" | |
validate_certs: false | |
wait_for_ip_address: | | |
{% if item['template'] is defined %}true{% else %}false{% endif %} | |
with_items: "{{ vms }}" | |
- name: Capturing VM Info | |
vmware_guest_facts: | |
datacenter: "{{ vcenter_datacenter }}" | |
folder: "/{{ vcenter_datacenter }}/vm" | |
hostname: "{{ vcenter_host }}" | |
name: "{{ item['name'] }}" | |
password: "{{ vcenter_password }}" | |
username: "{{ vcenter_username }}" | |
validate_certs: false | |
register: _vms_info | |
with_items: "{{ vms }}" | |
when: item['state']|lower == "present" | |
- name: Generating Dynamic Group | |
add_host: | |
ansible_host: "{{ item['instance']['ipv4'] }}" | |
groups: provisioned_vms | |
mac_address: "{{ item['instance']['hw_eth0']['macaddress_dash'] }}" | |
name: "{{ item['instance']['hw_name'] }}" | |
uuid: "{{ item['instance']['hw_product_uuid'] }}" | |
with_items: "{{ _vms_info['results'] }}" | |
when: > | |
item['skipped'] is not defined | |
- name: Generating Inventory | |
template: | |
src: ./hosts.inv.j2 | |
dest: ./hosts.inv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment