# 1st time using API with Ansible

**URL:** <https://forum.ansible.com/t/1st-time-using-api-with-ansible/36383>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [March 1, 2022, 7:10am UTC](https://forum.ansible.com/t/1st-time-using-api-with-ansible/36383 "2022-03-01T07:10:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 1, 2022, 7:10am UTC](https://forum.ansible.com/t/1st-time-using-api-with-ansible/36383/1 "2022-03-01T07:10:27Z")

</div>

> Hi everyone  
> I am trying to use Ansible for the first time with an API. Normally I have learned to manage a specific device with ansible where you are connecting to the device.
> 
> 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-design)
> 
> [https://www.redhat.com/sysadmin/deployment-ansible-automation](https://www.redhat.com/sysadmin/deployment-ansible-automation)
> 
> [https://www.redhat.com/sysadmin/deployment-ansible-playbooks](https://www.redhat.com/sysadmin/deployment-ansible-playbooks)
> 
> I have 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. (perhaps this was a generic placeholder?)
> 
> Please see the playbook and resulting run below.
> 
> - 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 variables
> 
> - name: Deploy VMs for certain site  
> shell:  
> cmd: ansible-playbook -e “vmchoice={{ [item.value.name](http://item.value.name) }}” --vault-password-file --vault-password-file /path/to/my/vault-password-file

This seems to supply --vault-password-file twice
