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 loop: "{{ vms.dict|dict2items }}" ignore_errors: yes when: item.value.system==system and site is undefined and system is defined [student@workstation ansible]$ ansible-playbook -e "system=ansible" many-vms.yml PLAY [Create Many VMs] ******************************************************************************************************************************************************************************************** TASK [Check if passwords.yml exists] ****************************************************************************************************************************************************************************** ok: [localhost] TASK [Check if file vms.csv exists] ******************************************************************************************************************************************************************************* ok: [localhost] TASK [Check if file vmtemplates.csv exists] *********************************************************************************************************************************************************************** ok: [localhost] TASK [Check if file vmflavours.csv exists] ************************************************************************************************************************************************************************ ok: [localhost] TASK [Check if file permissions.csv exists] *********************************************************************************************************************************************************************** ok: [localhost] TASK [Terminate the play is any variable file is missing] ********************************************************************************************************************************************************* skipping: [localhost] TASK [Parse vms.csv file] ***************************************************************************************************************************************************************************************** ok: [localhost] TASK [Test variables used to deploy multiple VMs] ***************************************************************************************************************************************************************** skipping: [localhost] TASK [Deploy VMs for certain site] ******************************************************************************************************************************************************************************** skipping: [localhost] => (item={'key': 'ansible01', 'value': {'name': 'ansible01', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.50.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible01.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible02', 'value': {'name': 'ansible02', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.55.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible02.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible03', 'value': {'name': 'ansible03', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.60.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible03.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible04', 'value': {'name': 'ansible04', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.65.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible04.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible05', 'value': {'name': 'ansible05', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.70.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible05.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible06', 'value': {'name': 'ansible06', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.75.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible06.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible07', 'value': {'name': 'ansible07', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.80.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible07.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible08', 'value': {'name': 'ansible08', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.85.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible08.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible09', 'value': {'name': 'ansible09', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.90.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible09.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) skipping: [localhost] => (item={'key': 'ansible10', 'value': {'name': 'ansible10', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.95.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible01.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) TASK [Deploy VMs for certain system] ****************************************************************************************************************************************************************************** failed: [localhost] (item={'key': 'ansible01', 'value': {'name': 'ansible01', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'eth0', 'ip': '172.30.50.50', 'gw': '172.30.50.1', 'mask': '255.255.255.0', 'system': 'ansible', 'fqdn': 'ansible01.idm.nac-issa.org', 'dns1': '172.30.50.5', 'dns2': '172.30.50.8', 'dns_domain': 'idm.nac-issa.org'}}) => {"ansible_loop_var": "item", "changed": true, "cmd": "ansible-playbook -e \"vmchoice=ansible01\" --vault-password-file vars/pwfile vars/passwords.yml", "delta": "0:00:00.647153", "end": "2022-02-28 15:30:13.735822", "item": {"key": "ansible01", "value": {"class": "server", "cluster": "Default", "dns1": "172.30.50.5", "dns2": "172.30.50.8", "dns_domain": "idm.nac-issa.org", "fqdn": "ansible01.idm.nac-issa.org", "gw": "172.30.50.1", "ip": "172.30.50.50", "mask": "255.255.255.0", "name": "ansible01", "nic": "eth0", "os": "rhel_8x64", "site": "Default", "system": "ansible", "type": "small", "vmflavour": "small_vm"}}, "msg": "non-zero return code", "rc": 4, "start": "2022-02-28 15:30:13.088669", "stderr": "ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead\n\nThe error appears to be in '/home/student/ansible/vars/passwords.yml': line 1, column 1, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n$ANSIBLE_VAULT;1.1;AES256\n^ here", "stderr_lines": ["ERROR! A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead", "", "The error appears to be in '/home/student/ansible/vars/passwords.yml': line 1, column 1, but may", "be elsewhere in the file depending on the exact syntax problem.", "", "The offending line appears to be:", "", "", "$ANSIBLE_VAULT;1.1;AES256", "^ here"], "stdout": "", "stdout_lines": []} ...REPEAT THE SAME FAILURE FOR THE NEXT 9 SYSTEMS... ...ignoring PLAY RECAP ******************************************************************************************************************************************************************************************************** localhost : ok=7 changed=1 unreachable=0 failed=0 skipped=3 rescued=0 ignored=1 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f0a7eb5-993f-4451-b2fb-ad6e54092189n%40googlegroups.com.
