Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result keyword usage in Conditional class in parsing.py #601

Open
wojtek0806 opened this issue Nov 16, 2023 · 0 comments
Open

result keyword usage in Conditional class in parsing.py #601

wojtek0806 opened this issue Nov 16, 2023 · 0 comments
Assignees

Comments

@wojtek0806
Copy link

SUMMARY

The conditonal class in parsing.py seems to require using result keyword when implemeting wait_for.

We have implemented wait_for in our collection, and we use Conditional class from plugins/module_utils/network/common/parsing.py

https://github.com/F5Networks/f5-ansible/blob/devel/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py#L504

A user raised an issue (F5Networks/f5-ansible#2380) where he seems to be forced to use results keyword when setting up wait_for conditions.

For example when we attempt to define wait_for conditon like so:

      bigip_command:
        commands: 
          - show sys failover
        wait_for:
          - sys_failover_state[0] contains 'Failover standby'
        provider: "{{ f5_provider }}"
        warn: no
        match: any
        retries: 60
        interval: 30
      register: sys_failover_state

We end up with the following error:

The full traceback is:
Traceback (most recent call last):
  File "/Users/wypior/.ansible/tmp/ansible-tmp-1700135387.177551-10764-33297694207417/AnsiballZ_bigip_command.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/wypior/.ansible/tmp/ansible-tmp-1700135387.177551-10764-33297694207417/AnsiballZ_bigip_command.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/wypior/.ansible/tmp/ansible-tmp-1700135387.177551-10764-33297694207417/AnsiballZ_bigip_command.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.f5networks.f5_modules.plugins.modules.bigip_command', init_globals=dict(_module_fqn='ansible_collections.f5networks.f5_modules.plugins.modules.bigip_command', _modlib_path=modlib_path),
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py", line 757, in <module>
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py", line 750, in main
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py", line 680, in exec_module
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py", line 634, in exec_module
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/f5networks/f5_modules/plugins/modules/bigip_command.py", line 513, in execute
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/parsing.py", line 235, in __call__
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/parsing.py", line 262, in get_value
  File "/tmp/ansible_bigip_command_payload_ck1sz0qc/ansible_bigip_command_payload.zip/ansible_collections/ansible/netcommon/plugins/module_utils/network/common/parsing.py", line 278, in get_json
KeyError: 'sys_failover_state'

Some output from the variables registed in the parsing.py:

 2.9s __call__: data=['Failover active for 0d 00:23:18']
 2.9s get_value: result={'result': ['Failover active for 0d 00:23:18']}
 2.9s get_json: result={'result': ['Failover active for 0d 00:23:18']}
 2.9s get_json: self.key='sys_failover_state[0]'
 2.9s get_json: key='sys_failover_state'

To fix the apparent problem, user needed to use result keyword:

    - name: Wait for active or standby status (means online)
      bigip_command:
        commands: 
          - show sys failover
        wait_for:
          - result[0] contains 'Failover active'
        provider: "{{ f5_provider }}"
        warn: no
        match: any
        retries: 60
        interval: 30
      register: sys_failover_state

Some output from the variables registered in the parsing.py:

 2.8s __call__: data=['Failover active for 0d 00:22:25']
 2.8s get_value: result={'result': ['Failover active for 0d 00:22:25']}
 2.8s get_json: result={'result': ['Failover active for 0d 00:22:25']}
 2.8s get_json: self.key='result[0]'
 2.8s get_json: key='result'

Is this expected, or maybe we have some issue in our implementation, i just do not see? If this is a bug or an improvement is required can we get this actioned?

ISSUE TYPE
  • Bug Report
COMPONENT NAME

https://github.com/ansible-collections/ansible.netcommon/blob/main/plugins/module_utils/network/common/parsing.py#L168

ANSIBLE VERSION
ansible [core 2.15.0]
  config file = /Users/wypior/devsettings/ansible.cfg
  configured module search path = ['/Users/wypior/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/wypior/environments/f5-ansible/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/wypior/Work/f5-ansible
  executable location = /Users/wypior/environments/f5-ansible/bin/ansible
  python version = 3.10.8 (main, Oct 13 2022, 10:19:13) [Clang 12.0.0 (clang-1200.0.32.29)] (/Users/wypior/environments/f5-ansible/bin/python)
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
Collection        Version
----------------- -------
ansible.netcommon 5.1.1  

CONFIGURATION
COLLECTIONS_PATHS(/Users/XXXXXXX/devsettings/ansible.cfg) = ['/Users/XXXXXXX/Work/f5-ansible']
CONFIG_FILE() = /Users/XXXXXXX/devsettings/ansible.cfg
DEFAULT_LOG_PATH(env: ANSIBLE_LOG_PATH) = /tmp/ansible.log
DEFAULT_ROLES_PATH(/Users/XXXXXXX/devsettings/ansible.cfg) = ['/Users/XXXXXXX/Work/f5-ansible/test/integration/targets']
DEPRECATION_WARNINGS(/Users/XXXXXXX/devsettings/ansible.cfg) = False
GALAXY_SERVER_LIST(/Users/XXXXXXX/devsettings/ansible.cfg) = ['automation_hub']
HOST_KEY_CHECKING(/Users/XXXXXXX/devsettings/ansible.cfg) = False
INVENTORY_ENABLED(/Users/XXXXXXX/devsettings/ansible.cfg) = ['yaml']
NETWORK_GROUP_MODULES(/Users/XXXXXXX/devsettings/ansible.cfg) = ['bigip', 'bigiq']
RETRY_FILES_ENABLED(/Users/XXXXXXX/devsettings/ansible.cfg) = False

STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants