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-designhttps://www.redhat.com/sysadmin/deployment-ansible-automation
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: permissionsfileCheck 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 undefinedParse Config files
- name: Parse vms.csv file
read_csv:
path: vars/vms.csv
key: name
register: vmsAll 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 undefinedIterate 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 }}” --vault-password-file --vault-password-file /path/to/my/vault-password-file
This seems to supply --vault-password-file twice