Pure-Storage-Ansible / FlashArray-Collection

Ansible Collection for Pure Storage FlashArray
GNU General Public License v3.0
19 stars 21 forks source link

purefa_info fails when gather set includes hosts or hgroups #455

Closed samuellay closed 9 months ago

samuellay commented 9 months ago

purefa_info fails on certain parameters

When the values passed to gather_subset include "all" "hosts" or "hgroups" the module fails in /ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 1289, in generate_host_dict\

or

ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2080, in generate_hgroups_dict\

To Reproduce

_purestorage_min_info.yml

---
- name: Discover Pure Array
  vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    user_name: ansibleuser
    ansible_password: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        36623134393235616264663036366137396263616533653935356138393261653533373363633235
        6635323930633564323334663335393335386332623266350a343038353462366537623538393334
        62363266346238663131393463616265653730363037393631353166336331383230316630303062
        3439313934636662660a303737656465633761393964616236653430633131616661386539666462
        6331
  hosts: "{{ array_name }}"
  connection: local
  gather_facts: False
  roles:
    - role: purestorage_min_info

roles/purestorage_min_info/tasks/main.yml

---
- name: Get the API token
  purestorage.flasharray.purefa_token:
    fa_url: "{{ ansible_host }}"
    username: "{{ user_name }}"
    password: "{{ ansible_password }}"
  register: result
  no_log: false

- name: Create API token variable
  ansible.builtin.set_fact:
    api_token: "{{ result.purefa_token }}"
  no_log: false

- name: Collect the array information [ all these work ]
  purestorage.flasharray.purefa_info:
    gather_subset:
      - minimum
#     - clients
#     - volumes
#     - hosts_balance
#     - interfaces
#     - pods
    fa_url: "{{ ansible_host }}"
    api_token: "{{ api_token }}"
  register: array_info
  when: api_token is defined and api_token
  no_log: false

- name: show
  debug:
    msg: "{{ array_info }}"
  when: api_token is defined and api_token
  no_log: false

- name: Collect all the array information [ all these fail ]
  purestorage.flasharray.purefa_info:
    gather_subset:
      - all
      - hgroups
      - hosts
    fa_url: "{{ ansible_host }}"
    api_token: "{{ api_token }}"
  register: array_info
  when: api_token is defined and api_token
  no_log: false

- name: show all
  debug:
    msg: "{{ array_info }}"
  when: api_token is defined and api_token
  no_log: false

If you use hosts or all you will get this error message:

TASK [purestorage_min_info : Collect all the array information] *********************************************************************
task path: /home/slay/ansible_projects/pure_init/roles/purestorage_min_info/tasks/main.yml:36
<pur09p99st001> ESTABLISH LOCAL CONNECTION FOR USER: slay
<pur09p99st001> EXEC /bin/sh -c 'echo ~slay && sleep 0'
<pur09p99st001> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/slay/.ansible/tmp `"&& mkdir "` echo /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614 `" && echo ansible-tmp-1695832049.4382265-77530-8033012201614="` echo /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614 `" ) && sleep 0'
Using module file /home/slay/.ansible/collections/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py
<pur09p99st001> PUT /home/slay/.ansible/tmp/ansible-local-774586j2srvu2/tmpijvj7zy3 TO /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py
<pur09p99st001> EXEC /bin/sh -c 'chmod u+x /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/ /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py && sleep 0'
<pur09p99st001> EXEC /bin/sh -c '/home/slay/venvs/env_pure/bin/python3 /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py && sleep 0'
<pur09p99st001> EXEC /bin/sh -c 'rm -f -r /home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/ > /dev/null 2>&1 && sleep 0'
fatal: [pur09p99st001]: FAILED! => {
    "changed": false,
    "module_stderr": "/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\nTraceback (most recent call last):\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695832049.4382265-77530-8033012201614/AnsiballZ_purefa_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.purestorage.flasharray.plugins.modules.purefa_info', init_globals=dict(_module_fqn='ansible_collections.purestorage.flasharray.plugins.modules.purefa_info', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_0rr44pby/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2363, in <module>\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_0rr44pby/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2288, in main\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_0rr44pby/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 1289, in generate_host_dict\nKeyError: 'pur08p99st001:syn09h99bl002'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

If you use hgroups you will get this:

TASK [purestorage_min_info : Collect all the array information] *********************************************************************
task path: /home/slay/ansible_projects/pure_init/roles/purestorage_min_info/tasks/main.yml:36
<pur09p99st001> ESTABLISH LOCAL CONNECTION FOR USER: slay
<pur09p99st001> EXEC /bin/sh -c 'echo ~slay && sleep 0'
<pur09p99st001> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/slay/.ansible/tmp `"&& mkdir "` echo /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643 `" && echo ansible-tmp-1695831955.2498972-77425-225233813427643="` echo /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643 `" ) && sleep 0'
Using module file /home/slay/.ansible/collections/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py
<pur09p99st001> PUT /home/slay/.ansible/tmp/ansible-local-773536lp_sf4z/tmp6rp_ibam TO /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py
<pur09p99st001> EXEC /bin/sh -c 'chmod u+x /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/ /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py && sleep 0'
<pur09p99st001> EXEC /bin/sh -c '/home/slay/venvs/env_pure/bin/python3 /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py && sleep 0'
<pur09p99st001> EXEC /bin/sh -c 'rm -f -r /home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/ > /dev/null 2>&1 && sleep 0'
fatal: [pur09p99st001]: FAILED! => {
    "changed": false,
    "module_stderr": "/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/slay/venvs/env_pure/lib/python3.10/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'pur09p99st001'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\nTraceback (most recent call last):\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/slay/.ansible/tmp/ansible-tmp-1695831955.2498972-77425-225233813427643/AnsiballZ_purefa_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.purestorage.flasharray.plugins.modules.purefa_info', init_globals=dict(_module_fqn='ansible_collections.purestorage.flasharray.plugins.modules.purefa_info', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_yq0nb920/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2363, in <module>\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_yq0nb920/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2296, in main\n  File \"/tmp/ansible_purestorage.flasharray.purefa_info_payload_yq0nb920/ansible_purestorage.flasharray.purefa_info_payload.zip/ansible_collections/purestorage/flasharray/plugins/modules/purefa_info.py\", line 2080, in generate_hgroups_dict\nKeyError: 'pur08p99st001:synpoclab'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
sdodsley commented 9 months ago

Please try #447 to see if that resolves your problem

sdodsley commented 9 months ago

You will also have to apply #446 as well for the hgroup issue

samuellay commented 9 months ago

Yes, this corrects my issue. Thank you!