Ist time using an API with Ansible

Hi everyone
I am trying to use Ansible for the first time with an API. Normally, I have learned to manage LInux servers with ansible where you are connecting to the device(s) using SSH and an inventory file.

I have been following this guide(s) to help provide some automation for oVirt virtualization.
https://www.redhat.com/sysadmin//deployment-ansible-design
https://www.redhat.com/sysadmin/deployment-ansible-automation
https://www.redhat.com/sysadmin/deployment-ansible-playbooks

I have generally copied what the author did except that I customized it for my environment.
When I try to run the playbook I am getting errors. My first question is what should the host parameter be listed as? Shouldn’t it be the oVirt manager? I see the article author chose to use localhost and I’m not sure why. Can someone explain? I’m still trying to get my head wrapped around it and understand what’s happening.

My file structre is as follows:
[student@workstation ansible]$ tree

├── many-vms.yml
└── vars
├── passwords.yml
├── permissions.csv
├── pwfile.txt
├── vmflavours.csv
├── vms.csv
└── vmtemplates.csv

Here is my playbook:

Hi everyone
I am trying to use Ansible for the first time with an API. Normally, I have learned to manage LInux servers with ansible where you are connecting to the device(s) using SSH and an inventory file.

I have been following this guide(s) to help provide some automation for oVirt virtualization.
https://www.redhat.com/sysadmin//deployment-ansible-design
https://www.redhat.com/sysadmin/deployment-ansible-automation
https://www.redhat.com/sysadmin/deployment-ansible-playbooks

I have generally copied what the author did except that I customized it for my environment.
When I try to run the playbook I am getting errors. My first question is what should the host parameter be listed as? Shouldn’t it be the oVirt manager? I see the article author chose to use localhost and I’m not sure why. Can someone explain? I’m still trying to get my head wrapped around it and understand what’s happening.

My file structre is as follows:
[student@workstation ansible]$ tree

├── many-vms.yml
└── vars
├── passwords.yml
├── permissions.csv
├── pwfile.txt
├── vmflavours.csv
├── vms.csv
└── vmtemplates.csv

Here is my playbook:

  • name: Create Many VMs
    hosts: localhost
    connection: local
    gather_facts: false
    tasks:

Check if all config files exist

  • name: Check if passwords.yml exists
    stat:
    path: vars/passwords.yml
    register: passwordsfile

  • name: Check if file vms.csv exists
    stat:
    path: vars/vms.csv
    register: vmsfile

  • name: Check if file vmtemplates.csv exists
    stat:
    path: vars/vmtemplates.csv
    register: vmtemplatesfile

  • name: Check if file vmflavours.csv exists
    stat:
    path: vars/vmflavours.csv

register: vmflavoursfile

  • name: Check if file permissions.csv exists
    stat:
    path: vars/permissions.csv
    register: permissionsfile

Check if there is a missing config file terminates the play

  • name: Terminate the play is any variable file is missing
    fail: msg=“Variable file is missing”
    when: passwordsfile.stat.exists is undefined or vmsfile.stat.exists is undefined or vmtemplatesfile.stat.exists is undefined or vmflavoursfile.stat.exists is undefined or permissionsfile.stat.exists is undefined

Parse Config files

  • name: Parse vms.csv file
    read_csv:
    path: vars/vms.csv
    key: name
    register: vms

All the variables are null, then terminate the play.

  • name: Test variables used to deploy multiple VMs
    fail: msg=“Please enter either site or system”
    when: site is undefined and system is undefined

Iterate Over the first and second plays based upon the non-null variabl

  • name: Deploy VMs for certain site
    shell:
    cmd: ansible-playbook -e “vmchoice={{ item.value.name }}” --vault-password-file vars/pwfile.txt vars/passwords.yml
    loop: “{{ vms.dict|dict2items }}”
    ignore_errors: yes
    when: item.value.site==site and site is defined and system is undefined

  • name: Deploy VMs for certain system
    shell:
    cmd: ansible-playbook -e “vmchoice={{ item.value.name }}” --vault-password-file vars/pwfile.txt vars/passwords.yml

You supplied a file called passwords.yml as the playbook. That sounds problematic, and indeed causes a failure.

BTW using ansible to run ansible through shell commands doesn’t seem like the easiest strategy to me…

BTW using ansible to run ansible through shell commands doesn’t seem like the easiest strategy to me…
I acknowledge this may not be the best way. I was following what somebody else did and just trying to see if it could work. I am VERY new to trying to run Ansible as part of a larger automation system and tying everything together so please forgive me. Baby steps when you have never done it before…

Right, I had some things wrong n the playbok. I updated the problem section and got much further.
Here is my updated playbook and resulting run of it.

Note: I did comment out a section in troubleshooting efforts. It looks like my problem is with this line but I am not quite sure how to correct it.
cmd: ansible-playbook -e “vmchoice={{ item.value.name }}” --vault-password-file vars/pwfile.txt many-vms.yml