I was in the middle of programming an Ansible playbook and suddenly I started getting a "Module Error" and I have no idea why. I tried each module individually in the CLI with every option. I ran a syntax check (--syntax-check
) and there were no problems with that. I think this mught be a bug.
"ios_facts" module works:
$ ansible all -m ios_facts -i Resources/Inventory/hosts
10.20.30.111 | SUCCESS => {
"ansible_facts": { "ansible_net_all_ipv4_addresses": [ "10.20.30.111" ], "ansible_net_all_ipv6_addresses": [], "ansible_net_filesystems": [ "flash:" (...)
"ios_ping" returns this error:
$ ansible all -m ios_ping -a"dest='1.1.1.1'" -i Resources/Inventory/hosts
10.20.30.111 | FAILED! => { "changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_WOH7nd/ansible_module_ios_ping.py\", line 215, in \n main()\n File \"/tmp/ansible_WOH7nd/ansible_module_ios_ping.py\", line 151, in main\n success, rx, tx, rtt = parse_ping(stats)\n File \"/tmp/ansible_WOH7nd/ansible_module_ios_ping.py\", line 200, in parse_ping\n return rate.group(\"pct\"), rate.group(\"rx\"), rate.group(\"tx\"), rtt.groupdict()\nAttributeError: 'NoneType' object has no attribute 'group'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
"ios_user" returns this error:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ASwitch#
10.20.30.111 | FAILED! => { "changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_UX9ZWc/ansible_module_ios_user.py\", line 409, in \n main()\n File \"/tmp/ansible_UX9ZWc/ansible_module_ios_user.py\", line 382, in main\n have = map_config_to_obj(module)\n File \"/tmp/ansible_UX9ZWc/ansible_module_ios_user.py\", line 242, in map_config_to_obj\n data = get_config(module, flags=['| section username'])\n File \"/tmp/ansible_UX9ZWc/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 117, in get_config\n File \"/tmp/ansible_UX9ZWc/ansible_modlib.zip/ansible/module_utils/connection.py\", line 146, in rpc\nansible.module_utils.connection.ConnectionError: show running-config | section username\r\n ^\r\n% Invalid input detected at '^' marker.\r\n\r\nASwitch#\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1 }
IOS config: config.text
Ansible Inventory: Resources/Inventory/hosts
Ansible Version: 2.5.0
Cisco IOS version: 12.2(55)SE
The connection works fine and I also was able to execute the "ios_system" module. Do you guys have any idea what this might be?
As it turns out, the ios_user
module is not compatible with Cisco IOS version 12.2(55)SE because it is using an output filter ("section
") which is not available for this device's version. To fix this, I just had to substitute the word "section
" with "include
" in the ansible/modules/network/ios/ios_user.py
file (the complete file path depends on your ansible instalation, because you might be using a virtual environment).
Here is the module code. So that part of the the code then looked like this:
def map_config_to_obj(module): data = get_config(module, flags=['| include username']) match = re.findall(r'^username (\S+)', data, re.M) if not match: return list()
The module now works as intendeed. As for the ios_ping
, I've been trying to reverse engineer it's code and, in my opinion, has more then one bug. I think it is working only when the success rate is above 0%
.