poweroff multiple vms inventory
[root@localhost ~]# cat multiple.yml
---
- hosts: all
gather_facts: false
connection: local
vars_prompt:
- name: "vsphere_password"
prompt: "vSphere Password"
- name: "notes"
prompt: "VM notes"
private: no
default: "Deployed with ansible"
tasks:
# get date
- set_fact: creationdate="{{lookup('pipe','date "+%Y/%m/%d %H:%M"')}}"
# Create a VM from a template
- name: poweroff the VMs
vmware_guest:
hostname: 192.168.0.103
username: root
password: vmware
validate_certs: no
esxi_hostname: 192.168.0.108
datacenter: dc
folder: /dc/vm
name: '{{ inventory_hostname }}'
state: poweredoff
guest_id: rhel6Guest
annotation: "{{ notes }} - {{ creationdate }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 256
num_cpus: 1
scsi: paravirtual
hostname: '{{ inventory_hostname }}'
template: temper
wait_for_ip_address: True
[root@localhost ~]#
root@localhost ~]# ansible-playbook -i multiple multiple.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *********************************************************************
TASK [set_fact] ****************************************************************
ok: [ans02]
ok: [ans04]
ok: [ans01]
ok: [ans03]
ok: [ans05]
ok: [ans07]
ok: [ans08]
ok: [ans06]
ok: [ans09]
ok: [ans10]
TASK [poweroff the VM] ***********************************************************
ok: [ans05]
ok: [ans02]
ok: [ans03]
ok: [ans01]
ok: [ans04]
ok: [ans07]
ok: [ans06]
ok: [ans09]
ok: [ans10]
ok: [ans08]
PLAY RECAP *********************************************************************
ans01 : ok=2 changed=0 unreachable=0 failed=0
ans02 : ok=2 changed=0 unreachable=0 failed=0
ans03 : ok=2 changed=0 unreachable=0 failed=0
ans04 : ok=2 changed=0 unreachable=0 failed=0
ans05 : ok=2 changed=0 unreachable=0 failed=0
ans06 : ok=2 changed=0 unreachable=0 failed=0
ans07 : ok=2 changed=0 unreachable=0 failed=0
ans08 : ok=2 changed=0 unreachable=0 failed=0
ans09 : ok=2 changed=0 unreachable=0 failed=0
ans10 : ok=2 changed=0 unreachable=0 failed=0
[root@localhost ~]#
---
- hosts: all
gather_facts: false
connection: local
vars_prompt:
- name: "vsphere_password"
prompt: "vSphere Password"
- name: "notes"
prompt: "VM notes"
private: no
default: "Deployed with ansible"
tasks:
# get date
- set_fact: creationdate="{{lookup('pipe','date "+%Y/%m/%d %H:%M"')}}"
# Create a VM from a template
- name: poweroff the VMs
vmware_guest:
hostname: 192.168.0.103
username: root
password: vmware
validate_certs: no
esxi_hostname: 192.168.0.108
datacenter: dc
folder: /dc/vm
name: '{{ inventory_hostname }}'
state: poweredoff
guest_id: rhel6Guest
annotation: "{{ notes }} - {{ creationdate }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 256
num_cpus: 1
scsi: paravirtual
hostname: '{{ inventory_hostname }}'
template: temper
wait_for_ip_address: True
[root@localhost ~]#
root@localhost ~]# ansible-playbook -i multiple multiple.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *********************************************************************
TASK [set_fact] ****************************************************************
ok: [ans02]
ok: [ans04]
ok: [ans01]
ok: [ans03]
ok: [ans05]
ok: [ans07]
ok: [ans08]
ok: [ans06]
ok: [ans09]
ok: [ans10]
TASK [poweroff the VM] ***********************************************************
ok: [ans05]
ok: [ans02]
ok: [ans03]
ok: [ans01]
ok: [ans04]
ok: [ans07]
ok: [ans06]
ok: [ans09]
ok: [ans10]
ok: [ans08]
PLAY RECAP *********************************************************************
ans01 : ok=2 changed=0 unreachable=0 failed=0
ans02 : ok=2 changed=0 unreachable=0 failed=0
ans03 : ok=2 changed=0 unreachable=0 failed=0
ans04 : ok=2 changed=0 unreachable=0 failed=0
ans05 : ok=2 changed=0 unreachable=0 failed=0
ans06 : ok=2 changed=0 unreachable=0 failed=0
ans07 : ok=2 changed=0 unreachable=0 failed=0
ans08 : ok=2 changed=0 unreachable=0 failed=0
ans09 : ok=2 changed=0 unreachable=0 failed=0
ans10 : ok=2 changed=0 unreachable=0 failed=0
[root@localhost ~]#
Comments
Post a Comment