ansible create vm from template and worked on all powerstates vcenter

https://docs.google.com/document/d/e/2PACX-1vQXcs6okYzpanWzl71zoQhrTLAPrv4TYi2L3EpZxQeTnKQd2LfGJR2mNZpqXJcF3tVNiUvnTb8IUDxm/pub#

https://docs.google.com/document/d/e/2PACX-1vRDVv3UQldEJ_-fhEVoKi64dyjToKg3ywhxPKd_LMVDxRG5RFycGKaBE1H6jGCtbhNmxJ6J_NNXu4S9/pub

 vi create.yml

---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template
    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm_2

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: present

      wait_for_ip_address: yes

[root@localhost ~]# vi create.yml
[root@localhost ~]# ansible-playbook create.yml

PLAY [Create a VM from a template] *********************************************

TASK [Clone the template] ******************************************************

changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0


---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template

    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm_1

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: absent

      wait_for_ip_address: yes


[root@localhost ~]# ansible-playbook delete.yml

PLAY [Create a VM from a template] *********************************************

TASK [Clone the template] ******************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0

[root@localhost ~]# vi delete.yml

created and deleted


create testvm
---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template

    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: present

      wait_for_ip_address: yes

poweredoff.yml


---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template

    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: poweredoff

      wait_for_ip_address: yes

vm testvm is poweredoff
[root@localhost ~]# ansible-playbook poweredoff.yml

PLAY [Create a VM from a template] *************************************************************************************************************************************

TASK [Clone the template] **********************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0


powered on test vm

poweredon.yml


---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template

    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: poweredon

      wait_for_ip_address: yes


[root@localhost ~]# ansible-playbook poweredon.yml

PLAY [Create a VM from a template] *************************************************************************************************************************************

TASK [Clone the template] **********************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

[root@localhost ~]#

reboot.yml

---

- name: Create a VM from a template

  hosts: localhost

  connection: local

  gather_facts: no

  tasks:

  - name: Clone the template

    vmware_guest:

      hostname: 192.168.45.151

      username: root

      password: vmware

      validate_certs: False

      name: testvm

      template: cent



      datacenter: dc

      folder: /dc/vm

      state: restarted

      wait_for_ip_address: yes


[root@localhost ~]# ansible-playbook delete.yml

PLAY [Create a VM from a template] *************************************************************************************************************************************

TASK [Clone the template] **********************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

state parameter =  absent,poweredoff,poweredon,present,rebootguest,restarted,shutdownguest,suspended, got: shutdown"

[root@localhost ~]# ansible-playbook delete.yml

PLAY [Create a VM from a template] *************************************************************************************************************************************

TASK [Clone the template] **********************************************************************************************************************************************
ok: [localhost]

PLAY RECAP *************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0

[root@localhost ~]#

Comments

Popular posts from this blog

ansible redhat cluster qorum qdevice

PE 3.9.0 on centos 6

gfs2 cluster