Hi,
I want to create a role that would do all of this tasks:
1. Create vm from template with preconfigured IP address
2. Modify vm parameters
3. Power up and wait for vm to be network reachable
4. Connect to newly created vm through template hardcoded IP and change its network settings
Now i don't want a static entry in inventory of vm template name and its ip as i want it both to be configured as role variable - in hosts i have specified only hypervisors IPs which it should run 1-3 tasks on but obviously the 4th task should be run on newly created VM reachable by templates IP.
How can i make the 4th task run solely on the new vm?
What would we the best possible route to achieve this?
---
- name: Running Create Virtual Machine Playbook
hosts: localhost
gather_facts: false
connection: local
tasks:
- name: Virtual Machine and customization
vmware_guest:
validate_certs: no
hostname: "{{ vcenter }}"
username: "{{ username }}"
password: "{{ password }}"
cluster : "{{ cluster }}"
datacenter: "{{ datacenter }}"
name: "{{ VM_Name }}"
folder: /
template: "{{ template }}"
state: poweredon
datastore: "{{ datastore }}"
disk:
- size_gb: 40
type: thin
datastore: "{{ datastore }}"
networks:
- name: "{{ network_name }}"
ip: "{{ ip }}"
netmask: "{{ netmask }}"
gateway: "{{ gateway }}"
dns_servers:
- 10.10.10.10
- 10.10.10.20
type: static
wait_for_ip_address: yes
wait_for_customization: yes
customization:
hostname: "{{ VM_Name }}"
dns_servers:
- 10.10.10.10
- 10.10.10.20
dns_suffix:
- localhost.com
- ap.localhost.com
domain: "{{ domain }}"
autologon: yes
password: "{{ local_pass }}"
runonce:
- powershell.exe -ExecutionPolicy Unrestricted wget https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile C:\Windows\Temp\ConfigureRemotingForAnsible.ps1
- powershell.exe -ExecutionPolicy Unrestricted -File C:\Windows\Temp\ConfigureRemotingForAnsible.ps1 -EnableCredSSP -DisableBasicAuth -Verbose
hardware:
memory_mb: "{{ mb }}"
num_cpus: "{{ cpu }}"
delegate_to: localhost