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

network_group_modules from ansible.cfg gets loaded incorrectly #26154

Closed
jmighion opened this issue Jun 27, 2017 · 6 comments · Fixed by #32460
Closed

network_group_modules from ansible.cfg gets loaded incorrectly #26154

jmighion opened this issue Jun 27, 2017 · 6 comments · Fixed by #32460
Assignees
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. cisco Cisco technologies discussion_topic This issue/PR includes a topic that requires a deeper discussion. Maybe raise this in a meeting? networking Network category nxos Cisco NXOS community support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Milestone

Comments

@jmighion
Copy link
Member

ISSUE TYPE
  • Bug Report
COMPONENT NAME

constants.py

ANSIBLE VERSION
 ansible --version
ansible 2.3.0.0
  config file = /home/jmighion/git/Ansible-Networking/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
CONFIGURATION
$ grep -v '#' ansible.cfg | grep  -e "\S"
[defaults]
inventory      = inventory
forks          = 1400
gather_subset = !ohai,!facter
gathering = smart
roles_path    = roles
host_key_checking = False
timeout = 20
log_path = ~/ansible.log
fact_caching = jsonfile
fact_caching_connection = ~/.cache/facts
fact_caching_timeout = 86400
retry_files_enabled = False
network_group_modules=['eos', 'nxos', 'ios', 'iosxr', 'junos', 'vyos']
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[accelerate]
[selinux]
[colors]
[diff]
OS / ENVIRONMENT

N/A

SUMMARY

If you use the network_group_modules option in ansible.cfg, it gets loaded incorrectly in constants.py. Even using the default that's provided in ansible.cfg, just using it will cause TaskExecutor._get_action_handler to load the wrong action plugin. I've been able to reproduce this on 2.3.0, 2.3.1, and devel 2.4.0 (3d6d428).

STEPS TO REPRODUCE

Remove the comment before the network_group_modules line in ansible.cfg :
network_group_modules=['eos', 'nxos', 'ios', 'iosxr', 'junos', 'vyos']

- name: dev
  hosts: all
  gather_facts: false
  connection: local
  tasks:
    - name: dev
      ios_facts:
        gather_subset:
          - "!interfaces"
        provider: "{{ cli }}"
EXPECTED RESULTS

Gather ios_facts
Added logging to show what C.NETWORK_GROUP_MODULES was :

Found module_prefix : ios
Found C.NETWORK_GROUP_MODULES : ['eos', 'nxos', 'ios', 'iosxr', 'junos', 'vyos', 'sros', 'dellos9', 'dellos10', 'dellos6']
ACTUAL RESULTS

Added logging to show what C.NETWORK_GROUP_MODULES was :

Found module_prefix : ios
Found C.NETWORK_GROUP_MODULES : [u"['eos'", u"'nxos'", u"'ios'", u"'iosxr'", u"'junos'", u"'vyos']"]
@gundalow gundalow added the networking Network category label Jun 27, 2017
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 27, 2017
@calfonso calfonso added this to the 2.4.0 milestone Jul 28, 2017
@calfonso calfonso added the discussion_topic This issue/PR includes a topic that requires a deeper discussion. Maybe raise this in a meeting? label Aug 4, 2017
@calfonso
Copy link
Contributor

@jmighion would you mind re-testing this in the devel branch? We believe it's fixed.

@rcarrillocruz
Copy link
Contributor

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Sep 8, 2017
@jmighion
Copy link
Member Author

jmighion commented Sep 8, 2017

I'll retest today hopefully. Sorry for the delay.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Sep 8, 2017
@jmighion
Copy link
Member Author

jmighion commented Sep 8, 2017

Still persists on this morning's devel. I tried from a mac and from rhel. I added the same logging to both hosts' ansible/executor/task_executor.py :

        module_prefix = self._task.action.split('_')[0]
        display.display('module_prefix : %s' % module_prefix)
        display.display('C.NETWORK_GROUP_MODULES : %s' % C.NETWORK_GROUP_MODULES)

        # let action plugin override module, fallback to 'normal' action plugin otherwise
        if self._task.action in self._shared_loader_obj.action_loader:
            handler_name = self._task.action
        elif all((module_prefix in C.NETWORK_GROUP_MODULES, module_prefix in self._shared_loader_obj.action_loader)):
            handler_name = module_prefix
        else:
            handler_name = 'normal'

        display.display('handler_name: %s' % handler_name)

Both hosts used the example ansible.cfg from the devel branch with only the following added :

$ grep -v '#' ansible.cfg | grep  -e "\S"
[defaults]
inventory      = hosts
host_key_checking = False
log_path = ./ansible.log
retry_files_enabled = False

From the mac :

$ ansible --version
 46233 1504892542.49112: starting run
ansible 2.5.0 (devel f58bd4f392) last updated 2017/09/08 09:46:04 (GMT -700)
  config file = /Users/james/Documents/Microsoft/local_ansible/ansible.cfg
  configured module search path = [u'/Users/james/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/james/Documents/git/ansible/lib/ansible
  executable location = /Users/james/Documents/git/ansible/bin/ansible
  python version = 2.7.13 (default, Jul 18 2017, 09:17:00) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

A run without using the network_group_modules option in ansible.cfg :

module_prefix : ios
C.NETWORK_GROUP_MODULES : ['eos', 'nxos', 'ios', 'iosxr', 'junos', 'ce', 'vyos', 'sros', 'dellos9', 'dellos10', 'dellos6', 'asa', 'aruba', 'aireos']
handler_name: ios

A run with the network_group_modules option in ansible.cfg added by just removing the comment :

module_prefix : ios
C.NETWORK_GROUP_MODULES : ["['eos'", "'nxos'", "'ios'", "'iosxr'", "'junos'", "'vyos']"]
handler_name: normal

From the rhel host :

$ ansible --version
 51278 1504892529.41093: starting run
ansible 2.5.0
  config file = /home/v-jamigh/git/Ansible-Networking/ansible.cfg
  configured module search path = [u'/home/v-jamigh/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/v-jamigh/tmp/ansible/lib/ansible
  executable location = /home/v-jamigh/tmp/ansible/bin/ansible
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]

The extra logging output was exactly the same. The handler_name was normal instead of ios. This creates the following error in the playbook run :

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_bHRUja/ansible_module_ios_command.py", line 234, in <module>
    main()
  File "/tmp/ansible_bHRUja/ansible_module_ios_command.py", line 203, in main
    responses = run_commands(module, commands)
  File "/tmp/ansible_bHRUja/ansible_modlib.zip/ansible/module_utils/ios.py", line 111, in run_commands
  File "/tmp/ansible_bHRUja/ansible_modlib.zip/ansible/module_utils/connection.py", line 66, in exec_command
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
TypeError: argument must be string or read-only character buffer, not None

fatal: [tusredrwec23u1]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_bHRUja/ansible_module_ios_command.py\", line 234, in <module>\n    main()\n  File \"/tmp/ansible_bHRUja/ansible_module_ios_command.py\", line 203, in main\n    responses = run_commands(module, commands)\n  File \"/tmp/ansible_bHRUja/ansible_modlib.zip/ansible/module_utils/ios.py\", line 111, in run_commands\n  File \"/tmp/ansible_bHRUja/ansible_modlib.zip/ansible/module_utils/connection.py\", line 66, in exec_command\n  File \"/usr/lib64/python2.7/socket.py\", line 224, in meth\n    return getattr(self._sock,name)(*args)\nTypeError: argument must be string or read-only character buffer, not None\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
}

Notice the difference in how the C.NETWORK_GROUP_MODULES is shown / typed. I wonder if the problem is how the group is formatted in the ansible.cfg or how it's pulled in / set in constants.

@calfonso calfonso modified the milestones: 2.5.0, 2.4.0 Sep 12, 2017
@bcoca
Copy link
Member

bcoca commented Nov 1, 2017

Possible Misunderstanding

Hi!

Thanks very much for your submission to Ansible. It sincerely means a lot to us.

We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.

The configuration is not loaded incorrectly, you are just mixing python/yaml with ini formats.
Ini does not support ['el1', 'el2'] as a list, use:

network_group_modules=eos, nxos, ios, iosxr, junos, vyos

In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.

Thank you once again for this and your interest in Ansible!

@bcoca bcoca closed this as completed Nov 1, 2017
@jmighion
Copy link
Member Author

jmighion commented Nov 1, 2017

Should this ticket be opened against ansible.cfg?
What was highlighted here was that the defaults in the config are incorrect and if you use the defaults they will break as described above.

jmighion added a commit to jmighion/ansible that referenced this issue Nov 1, 2017
…railing whitespaces from comments for style consistency. Fixes ansible#26154
caphrim007 pushed a commit to caphrim007/ansible that referenced this issue Nov 1, 2017
…railing whitespaces from comments for style consistency. Fixes ansible#26154 (ansible#32460)
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@dagwieers dagwieers added the nxos Cisco NXOS community label Feb 22, 2019
@dagwieers dagwieers added the cisco Cisco technologies label Feb 23, 2019
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. cisco Cisco technologies discussion_topic This issue/PR includes a topic that requires a deeper discussion. Maybe raise this in a meeting? networking Network category nxos Cisco NXOS community support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants