Ansible Playbook help

Posted on

Hi All,

I'm new yaml and Ansible and I have been trying to experiment with it to some very basic tasks but struggling with it.

The system I'm using to run the playbook on is CentOS 7 with Ansible 2.8 installed and the ovirt-ansible packages and the python ovirt engine sdk 4 version 4.3, this is connecting to my RHM.

So far the playbook is just shutting down one VM, the code I have thus far is

- name: Shutdown VM
  hosts: localhost
    - engine_vars.yml
    - password.yml

    - name: Login into RHV
        url: "{{ engine_url }}"
        username: "{{ engine_user }}"
        password: "{{ engine_password }}"
        ca_file: "{{ engine_cafile | default(omit) }}"
        insecure: "{{ engine_insecure | default(true) }}"
        - always

    - name: Shutdown QSTMS21
        auth: "{{ ovirt_auth }}"
        name: QSTMS21
        state: stopped

    - name: Revoke password
        state: absent
        ovirt_auth: "{{ ovirt_auth }}"

However I'm wanting to take this a little further but getting stuck on how to do it and would appreciate some help/guidance, I would like the playbook to:
1. Connect to host
2. Shutdown all running VM's on that host only
3. Do a yum update
3. Reboot Host and wait 10mins for it come back up
4. Start all VMs.

It seems I need to use loops but struggling how to get the current VM's and store them as a variable to pass back later.

Kind Regards