ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.96k stars 23.91k forks source link

Subsequent calls to purefa_facts in a playbook overrides the results of the previous run #53128

Closed lndevnull closed 5 years ago

lndevnull commented 5 years ago
SUMMARY

Subsequent calls to purefa_facts in a playbook overrides the ansible_purefa_facts dict rather than merging

ISSUE TYPE
COMPONENT NAME

lib/ansible/modules/storage/purestorage/purefa_facts.py

ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  1 2018, 03:12:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36.0.1)]
CONFIGURATION
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /var/log/ansible.log
PARAMIKO_HOST_KEY_AUTO_ADD(/etc/ansible/ansible.cfg) = True
RETRY_FILES_SAVE_PATH(/etc/ansible/ansible.cfg) = /home/homedir/.ansible-retry
OS / ENVIRONMENT
STEPS TO REPRODUCE

Run purefa_facts in a loop and rather than merging or appending the facts are overwritten. This can be an issue if you're trying to pull facts from multiple PureStorage endpoints.

vars:
  pure_fa_cfg:                                                                                                                  
    purestorage_cluster1:                                                                                                                 
      fa_url: purestorage_cluster1
      api_token: secret_token1
    purestorage_cluster2:                                                                                                                 
      fa_url: purestorage_cluster2 
      api_token: secret_token2

tasks:
  - purefa_facts:
      fa_url: "{{ item.value.fa_url }}"
      api_token: "{{ item.value.api_token }}"
      gather_subset:
        - volumes
    loop: "{{ pure_fa_cfg|dict2items }}"
    delegate_to: localhost

  - debug: var=hostvars[inventory_hostname][\"ansible_facts\"][\"purefa_facts\"][\"volumes\"]
EXPECTED RESULTS

I would expect that the hostvars[inventory_hostname][\"ansible_facts\"][\"purefa_facts\"][\"volumes\"] dict be append to rather than overwritten. This may not be best practice so I would be open to ideas on how to handle it.

ACTUAL RESULTS
ansibot commented 5 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibot commented 5 years ago

cc @bannaych @genegr @lionmax @raekins @sdodsley @sile16 click here for bot help

ansibot commented 5 years ago

cc @opslounge click here for bot help

ansibot commented 5 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibot commented 5 years ago

cc @dnix101 click here for bot help

ansibot commented 5 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

sdodsley commented 5 years ago

@lndevnull As you can see purefa_facts is going to be deprecated in favour of purefa_info as per the new requirements from the core team. You may want to try something along these lines:

  vars:
    pure_fa_cfg:
      purestorage_cluster1:
        fa_url: purestorage_cluster1
        api_token: secret_token_1
      purestorage_cluster2:
        fa_url: purestorage_cluster2
        api_token: secret_token_2

  tasks:
    - purefa_info:
        fa_url: "{{ item.value.fa_url }}"
        api_token: "{{ item.value.api_token }}"
        gather_subset:
          - volumes
      register: volumes
      with_items: "{{ pure_fa_cfg|dict2items }}"
      delegate_to: localhost

    - debug: var={{item.purefa_info.volumes}}
      with_items: "{{volumes.results}}"
sdodsley commented 5 years ago

notabug