root@localhost ~]# cat createvms
[web-vms]
ans-web[01:05] disk='10' datastore='datastore1' memory='512' cpucount='1' guest_id='centos64Guest'
[root@localhost ~]#
[root@localhost ~]# cat zing.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: create the VM
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: present
guest_id: centos64Guest
annotation: "{{ notes }} - {{ creationdate }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 512
num_cpus: 1
hostname: '{{ inventory_hostname }}'
[root@localhost ~]# ansible-playbook -i createvms zing.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web03]
ok: [ans-web04]
ok: [ans-web05]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web02]
changed: [ans-web03]
changed: [ans-web05]
changed: [ans-web04]
changed: [ans-web01]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
[root@localhost ~]#
[root@localhost ~]# vi zing.yml where state=abent
[root@localhost ~]# ansible-playbook -i createvms zing.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web03]
ok: [ans-web04]
ok: [ans-web05]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web03]
changed: [ans-web04]
changed: [ans-web05]
changed: [ans-web01]
changed: [ans-web02]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
[root@localhost ~]#
[web-vms]
ans-web[01:05] disk='10' datastore='datastore1' memory='512' cpucount='1' guest_id='centos64Guest'
[root@localhost ~]#
[root@localhost ~]# cat zing.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: create the VM
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: present
guest_id: centos64Guest
annotation: "{{ notes }} - {{ creationdate }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 512
num_cpus: 1
hostname: '{{ inventory_hostname }}'
[root@localhost ~]# ansible-playbook -i createvms zing.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web03]
ok: [ans-web04]
ok: [ans-web05]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web02]
changed: [ans-web03]
changed: [ans-web05]
changed: [ans-web04]
changed: [ans-web01]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
[root@localhost ~]#
[root@localhost ~]# vi zing.yml where state=abent
[root@localhost ~]# ansible-playbook -i createvms zing.yml
vSphere Password:
VM notes [Deployed with ansible]:
PLAY [all] *******************************************************************************************************************************************
TASK [set_fact] **************************************************************************************************************************************
ok: [ans-web01]
ok: [ans-web02]
ok: [ans-web03]
ok: [ans-web04]
ok: [ans-web05]
TASK [create the VM] *********************************************************************************************************************************
changed: [ans-web03]
changed: [ans-web04]
changed: [ans-web05]
changed: [ans-web01]
changed: [ans-web02]
PLAY RECAP *******************************************************************************************************************************************
ans-web01 : ok=2 changed=1 unreachable=0 failed=0
ans-web02 : ok=2 changed=1 unreachable=0 failed=0
ans-web03 : ok=2 changed=1 unreachable=0 failed=0
ans-web04 : ok=2 changed=1 unreachable=0 failed=0
ans-web05 : ok=2 changed=1 unreachable=0 failed=0
[root@localhost ~]#
Comments
Post a Comment