Ist time using an API with Ansible

42 views
Skip to first unread message

Jeremy Tourville

unread,
Feb 28, 2022, 4:43:51 PM2/28/22
to Ansible Project
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   

Dick Visser

unread,
Mar 1, 2022, 2:25:49 AM3/1/22
to ansible...@googlegroups.com
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..


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f0a7eb5-993f-4451-b2fb-ad6e54092189n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Jeremy Tourville

unread,
Mar 1, 2022, 9:43:30 AM3/1/22
to Ansible Project
>>>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


  #- 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

    - name: Deploy VMs for certain system
      shell:
        cmd: ansible-playbook -e "vmchoice={{ item.value.name }}" --vault-password-file vars/pwfile.txt many-vms.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 -vvvv
ansible-playbook 2.9.27
  config file = /home/student/ansible/ansible.cfg
  configured module search path = ['/home/student/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.8 (default, Mar 19 2021, 05:13:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
Using /home/student/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3.6/site-packages/ansible/plugins/callback/default.py
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: many-vms.yml ***************************************************************************************************************************************************************************************
Positional arguments: many-vms.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
extra_vars: ('system=ansible',)
forks: 5
1 plays in many-vms.yml


PLAY [Create Many VMs] ***************************************************************************************************************************************************************************************
META: ran handlers


TASK [Check if passwords.yml exists] *************************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880 `" && echo ansible-tmp-1646118141.3993182-118078-60314346191880="` echo /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/stat.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmp0x406_wk TO /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880/ /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118141.3993182-118078-60314346191880/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "vars/passwords.yml"
        }
    },
    "stat": {
        "atime": 1646093853.752343,
        "attr_flags": "",
        "attributes": [],
        "block_size": 4096,
        "blocks": 8,
        "charset": "us-ascii",
        "checksum": "e8654355048d76efe73e3705452ae794efcadd06",
        "ctime": 1646093846.4864788,
        "dev": 64770,
        "device_type": 0,
        "executable": false,
        "exists": true,
        "gid": 1001,
        "gr_name": "student",
        "inode": 50332516,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mimetype": "text/plain",
        "mode": "0644",
        "mtime": 1646093846.4864788,
        "nlink": 1,
        "path": "vars/passwords.yml",
        "pw_name": "student",
        "readable": true,
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 743,
        "uid": 1001,
        "version": "671336638",
        "wgrp": false,
        "woth": false,
        "writeable": true,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false

    }
}

TASK [Check if file vms.csv exists] **************************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:14
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911 `" && echo ansible-tmp-1646118141.8026433-118096-237829901909911="` echo /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/stat.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmpt995d9fx TO /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911/ /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118141.8026433-118096-237829901909911/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "vars/vms.csv"
        }
    },
    "stat": {
        "atime": 1646114089.4561672,
        "attr_flags": "",
        "attributes": [],
        "block_size": 4096,
        "blocks": 8,
        "charset": "us-ascii",
        "checksum": "8c52dd33738570446885b646531a8cc9854eaf3d",
        "ctime": 1646114012.6135578,
        "dev": 64770,
        "device_type": 0,
        "executable": false,
        "exists": true,
        "gid": 1001,
        "gr_name": "student",
        "inode": 50332508,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mimetype": "text/plain",
        "mode": "0664",
        "mtime": 1646114012.6095579,
        "nlink": 1,
        "path": "vars/vms.csv",
        "pw_name": "student",
        "readable": true,
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 990,
        "uid": 1001,
        "version": "1021740466",
        "wgrp": true,
        "woth": false,
        "writeable": true,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false

    }
}

TASK [Check if file vmtemplates.csv exists] ******************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:19
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046 `" && echo ansible-tmp-1646118142.051211-118114-1385553041046="` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/stat.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmpkpywd0ep TO /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046/ /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118142.051211-118114-1385553041046/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "vars/vmtemplates.csv"
        }
    },
    "stat": {
        "atime": 1646101580.6560037,
        "attr_flags": "",
        "attributes": [],
        "block_size": 4096,
        "blocks": 8,
        "charset": "us-ascii",
        "checksum": "eb3833f421ed854d26d1cbe03fca3951919225b0",
        "ctime": 1646101500.141491,
        "dev": 64770,
        "device_type": 0,
        "executable": false,
        "exists": true,
        "gid": 1001,
        "gr_name": "student",
        "inode": 50332513,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mimetype": "text/plain",
        "mode": "0664",
        "mtime": 1646101500.1164913,
        "nlink": 1,
        "path": "vars/vmtemplates.csv",
        "pw_name": "student",
        "readable": true,
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 59,
        "uid": 1001,
        "version": "1390502897",
        "wgrp": true,
        "woth": false,
        "writeable": true,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false

    }
}

TASK [Check if file vmflavours.csv exists] *******************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:24
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758 `" && echo ansible-tmp-1646118142.2881463-118132-21155654550758="` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/stat.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmpic2s7sm9 TO /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758/ /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118142.2881463-118132-21155654550758/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "vars/vmflavours.csv"
        }
    },
    "stat": {
        "atime": 1646093929.6138542,
        "attr_flags": "",
        "attributes": [],
        "block_size": 4096,
        "blocks": 8,
        "charset": "us-ascii",
        "checksum": "f2ceef2a42556a6459b6589401741dceec4e2ad9",
        "ctime": 1646093924.9189432,
        "dev": 64770,
        "device_type": 0,
        "executable": false,
        "exists": true,
        "gid": 1001,
        "gr_name": "student",
        "inode": 50332514,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mimetype": "text/plain",
        "mode": "0664",
        "mtime": 1646093924.9019434,
        "nlink": 1,
        "path": "vars/vmflavours.csv",
        "pw_name": "student",
        "readable": true,
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 83,
        "uid": 1001,
        "version": "2579530209",
        "wgrp": true,
        "woth": false,
        "writeable": true,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false

    }
}

TASK [Check if file permissions.csv exists] ******************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:29
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126 `" && echo ansible-tmp-1646118142.5333438-118150-108808795902126="` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/stat.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmp6v078k10 TO /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126/ /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126/AnsiballZ_stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118142.5333438-118150-108808795902126/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "checksum_algorithm": "sha1",
            "follow": false,
            "get_attributes": true,
            "get_checksum": true,
            "get_md5": false,
            "get_mime": true,
            "path": "vars/permissions.csv"
        }
    },
    "stat": {
        "atime": 1646095095.2363718,
        "attr_flags": "",
        "attributes": [],
        "block_size": 4096,
        "blocks": 8,
        "charset": "us-ascii",
        "checksum": "7ee1f462d2c937955fc57814e69c14ac532ba477",
        "ctime": 1646095073.1147647,
        "dev": 64770,
        "device_type": 0,
        "executable": false,
        "exists": true,
        "gid": 1001,
        "gr_name": "student",
        "inode": 50332512,
        "isblk": false,
        "ischr": false,
        "isdir": false,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": true,
        "issock": false,
        "isuid": false,
        "mimetype": "text/plain",
        "mode": "0664",
        "mtime": 1646095073.1117647,
        "nlink": 1,
        "path": "vars/permissions.csv",
        "pw_name": "student",
        "readable": true,
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 68,
        "uid": 1001,
        "version": "2310760465",
        "wgrp": true,
        "woth": false,
        "writeable": true,
        "wusr": true,
        "xgrp": false,
        "xoth": false,
        "xusr": false

    }
}

TASK [Terminate the play is any variable file is missing] ****************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:35
skipping: [localhost] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}

TASK [Parse vms.csv file] ************************************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:40
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996 `" && echo ansible-tmp-1646118142.8559139-118170-14340145739996="` echo /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/read_csv.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmp1oqya1u9 TO /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996/AnsiballZ_read_csv.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996/ /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996/AnsiballZ_read_csv.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996/AnsiballZ_read_csv.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118142.8559139-118170-14340145739996/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "dict": {
        "ansible01": {

            "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": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        },
        "ansible02": {

            "class": "server",
            "cluster": "Default",
            "dns1": "172.30.50.5",
            "dns2": "172.30.50.8",
            "dns_domain": "idm.nac-issa.org",
            "fqdn": "ansible02.idm.nac-issa.org",
            "gw": "172.30.50.1",
            "ip": "172.30.50.55",
            "mask": "255.255.255.0",
            "name": "ansible02",
            "nic": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        },
        "ansible03": {

            "class": "server",
            "cluster": "Default",
            "dns1": "172.30.50.5",
            "dns2": "172.30.50.8",
            "dns_domain": "idm.nac-issa.org",
            "fqdn": "ansible03.idm.nac-issa.org",
            "gw": "172.30.50.1",
            "ip": "172.30.50.60",
            "mask": "255.255.255.0",
            "name": "ansible03",
            "nic": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        },
        "ansible04": {

            "class": "server",
            "cluster": "Default",
            "dns1": "172.30.50.5",
            "dns2": "172.30.50.8",
            "dns_domain": "idm.nac-issa.org",
            "fqdn": "ansible04.idm.nac-issa.org",
            "gw": "172.30.50.1",
            "ip": "172.30.50.65",
            "mask": "255.255.255.0",
            "name": "ansible04",
            "nic": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        },
        "ansible05": {

            "class": "server",
            "cluster": "Default",
            "dns1": "172.30.50.5",
            "dns2": "172.30.50.8",
            "dns_domain": "idm.nac-issa.org",
            "fqdn": "ansible05.idm.nac-issa.org",
            "gw": "172.30.50.1",
            "ip": "172.30.50.70",
            "mask": "255.255.255.0",
            "name": "ansible05",
            "nic": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        }
    },
    "invocation": {
        "module_args": {
            "delimiter": null,
            "dialect": "excel",
            "fieldnames": null,
            "key": "name",
            "path": "vars/vms.csv",
            "skipinitialspace": null,
            "strict": null,
            "unique": true
        }
    },
    "list": []

}

TASK [Test variables used to deploy multiple VMs] ************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:47
skipping: [localhost] => {
    "changed": false,
    "skip_reason": "Conditional result was False"

}

TASK [Deploy VMs for certain system] *************************************************************************************************************************************************************************
task path: /home/student/ansible/many-vms.yml:59
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: student
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/student/.ansible/tmp `"&& mkdir "` echo /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873 `" && echo ansible-tmp-1646118143.3148215-118188-83124451860873="` echo /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/commands/command.py
<127.0.0.1> PUT /home/student/.ansible/tmp/ansible-local-1180726_af60ks/tmpntzxmqua TO /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873/AnsiballZ_command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873/ /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/student/.ansible/tmp/ansible-tmp-1646118143.3148215-118188-83124451860873/ > /dev/null 2>&1 && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'echo ~student && sleep 0'
failed: [localhost] (item={'key': 'ansible01', 'value': {'name': 'ansible01', 'vmflavour': 'small_vm', 'type': 'small', 'site': 'Default', 'cluster': 'Default', 'class': 'server', 'os': 'rhel_8x64', 'nic': 'enp1s0', '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.txt many-vms.yml",
    "delta": "0:00:02.538989",
    "end": "2022-03-01 01:02:26.147334",
    "invocation": {
        "module_args": {
            "_raw_params": "ansible-playbook -e \"vmchoice=ansible01\" --vault-password-file vars/pwfile.txt many-vms.yml",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true

        }
    },
    "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": "enp1s0",

            "os": "rhel_8x64",
            "site": "Default",
            "system": "ansible",
            "type": "small",
            "vmflavour": "small_vm"
        }
    },
    "msg": "non-zero return code",
    "rc": 2,
    "start": "2022-03-01 01:02:23.608345",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "\nPLAY [Create Many VMs] *********************************************************\n\nTASK [Check if passwords.yml exists] *******************************************\nok: [localhost]\n\nTASK [Check if file vms.csv exists] ********************************************\nok: [localhost]\n\nTASK [Check if file vmtemplates.csv exists] ************************************\nok: [localhost]\n\nTASK [Check if file vmflavours.csv exists] *************************************\nok: [localhost]\n\nTASK [Check if file permissions.csv exists] ************************************\nok: [localhost]\n\nTASK [Terminate the play is any variable file is missing] **********************\nskipping: [localhost]\n\nTASK [Parse vms.csv file] ******************************************************\nok: [localhost]\n\nTASK [Test variables used to deploy multiple VMs] ******************************\nfatal: [localhost]: FAILED! => {\"changed\": false, \"msg\": \"Please enter either site or system\"}\n\nPLAY RECAP *********************************************************************\nlocalhost                  : ok=6    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0   ",
    "stdout_lines": [
        "",
        "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] ******************************",
        "fatal: [localhost]: FAILED! => {\"changed\": false, \"msg\": \"Please enter either site or system\"}",
        "",
        "PLAY RECAP *********************************************************************",
        "localhost                  : ok=6    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0   "
    ]
}

...REPEAT THE SAME FAILURE FOR THE NEXT X SYSTEMS...

...ignoring
META: ran handlers
META: ran handlers

PLAY RECAP ***************************************************************************************************************************************************************************************************
localhost                  : ok=7    changed=1    unreachable=0    failed=0    skipped=2    rescued=0    ignored=1  

Reply all
Reply to author
Forward
0 new messages