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-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: 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 }}" --vault-password-file --vault-password-file /path/to/my/vault-password-file 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 --vault-password-file /path/to/my/vault-password-file 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 "site=Default" --ask-vault-pass many-vms.yml Vault password: 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] ********************************************************************************************************************************************************** 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 --vault-password-file /path/to/my/vault-password-file", "delta": "0:00:00.426266", "end": "2022-02-25 14:44:24.057347", "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": 2, "start": "2022-02-25 14:44:23.631081", "stderr": "usage: ansible-playbook [-h] [--version] [-v] [-k]\n [--private-key PRIVATE_KEY_FILE] [-u REMOTE_USER]\n [-c CONNECTION] [-T TIMEOUT]\n [--ssh-common-args SSH_COMMON_ARGS]\n [--sftp-extra-args SFTP_EXTRA_ARGS]\n [--scp-extra-args SCP_EXTRA_ARGS]\n [--ssh-extra-args SSH_EXTRA_ARGS] [--force-handlers]\n [--flush-cache] [-b] [--become-method BECOME_METHOD]\n [--become-user BECOME_USER] [-K] [-t TAGS]\n [--skip-tags SKIP_TAGS] [-C] [--syntax-check] [-D]\n [-i INVENTORY] [--list-hosts] [-l SUBSET]\n [-e EXTRA_VARS] [--vault-id VAULT_IDS]\n [--ask-vault-pass | --vault-password-file VAULT_PASSWORD_FILES]\n [-f FORKS] [-M MODULE_PATH] [--list-tasks]\n [--list-tags] [--step] [--start-at-task START_AT_TASK]\n playbook [playbook ...]\nansible-playbook: error: argument --vault-password-file: expected one argument", "stderr_lines": ["usage: ansible-playbook [-h] [--version] [-v] [-k]", " [--private-key PRIVATE_KEY_FILE] [-u REMOTE_USER]", " [-c CONNECTION] [-T TIMEOUT]", " [--ssh-common-args SSH_COMMON_ARGS]", " [--sftp-extra-args SFTP_EXTRA_ARGS]", " [--scp-extra-args SCP_EXTRA_ARGS]", " [--ssh-extra-args SSH_EXTRA_ARGS] [--force-handlers]", " [--flush-cache] [-b] [--become-method BECOME_METHOD]", " [--become-user BECOME_USER] [-K] [-t TAGS]", " [--skip-tags SKIP_TAGS] [-C] [--syntax-check] [-D]", " [-i INVENTORY] [--list-hosts] [-l SUBSET]", " [-e EXTRA_VARS] [--vault-id VAULT_IDS]", " [--ask-vault-pass | --vault-password-file VAULT_PASSWORD_FILES]", " [-f FORKS] [-M MODULE_PATH] [--list-tasks]", " [--list-tags] [--step] [--start-at-task START_AT_TASK]", " playbook [playbook ...]", "ansible-playbook: error: argument --vault-password-file: expected one argument"], "stdout": "", "stdout_lines": []} ... ansible02, 03, etc ...ignoring TASK [Deploy VMs for certain system] ******************************************************************************************************************************************************** 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'}}) 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/9237121a-028b-47c9-ab2d-1bfbc945256dn%40googlegroups.com.
