napalm-automation/napalm-ansible

napalm Collection on AWX 19.0.0

barryconstantly opened this issue · 9 comments

I am using the napalm_install_config function in my ansible command line playbook and it is working fine. I am using ansible napalm modules in this scenario.

Migrating to AWX which is my normal workflow, I followed the instructions to sync collections using requirements.yml. Note that this file is in my repo and under the collections folder:


collections:

  • cisco.ios
  • napalm.napalm

When I run the AWX template which calls the playbook, I get this error:

{"msg": "the python module napalm is required",}

Note the my cisco.ios collection specified in requirements.yml works in another playbook.

Also note that AWX is in a Docker container and managed by kubernties.

This is the playbook:


  • name: NAPALM gather information on IOS
    hosts: 10.1.151.10

    tasks:

    • name: Install Config and save diff
      napalm.napalm.napalm_install_config:
      hostname: '{{ inventory_hostname }}'
      username: admin
      password: riverbed
      optional_args: {'secret': 'riverbed', 'inline_transfer': 'True'}
      dev_os: ios
      config_file: 'ansible_running_config_1.txt'
      replace_config: True
      commit_changes: True
      archive_file: True
      get_diffs: True
      diff_file: 'diff.txt'

Did you pip install napalm?

See install section here (you might need to click on the full readme):

https://galaxy.ansible.com/napalm/napalm

Since AWX is released as a Docker container, it cannot be done like I would with Tower which is supported on a VM (and this would be considered a workaround as well even on Tower).

You are supposed to be able to include in my requirements.yml file as I am doing.

The strange thing is that before I had it defined in my requirements.yml, I got this message: "ERROR! couldn't resolve module/action 'napalm.napalm.napalm_install_config'. This often indicates a misspelling, missing collection, or incorrect module path."

After placing napalm.napalm in my requirements file it gets alot farther and then errors out with the originally posted message, repasted here:

"{ "msg": "the python module napalm is required",....}

Since this is docker, would it not be the correct approach for this to work when it loads the collection from requirements.yml?

IIRC requirements.yml is only for collections/roles and does not include Python dependencies (which napalm is). I believe that is correct from reading on it, but if that is incorrect, just let me know.

Your first error above indicates that you didn't have the napalm.napalm collection installed. Your second error above indicates you do not have the NAPALM library installed (python library).

On just Ansible (not AWX/not tower) the installation process is:

pip install napalm
ansible-galaxy collection install napalm.napalm

I am not a programmer, so bear with me. This is from Tower concerning collections:

  1. Install the collection into your runtime environment or virtual environment (my comment, complicated if possible for Docker)
  2. Provide the collection as part of your SCM tree (I am going to explore this option next..)
  3. Use a requirements file (tried this, did not work)

Sorry for another post. This is Tower documentation regarding the inclusion of collection in requirements.yml:

"Launching this job template results in the collections being pulled down from Automation Hub and Galaxy and invoking modules made available through those collections"

I thought this implies that modules are supposed to be pulled down as well?

Sorry, I am not a developer if these are dumb questions

Hi Kirk,

I moved away from AWX and installed evaluation version of Tower which runs on normal VM.

Then I did these steps:

  • pip3 install napalm
  • In my hosts file, added this variable since this is CentOS and ansible ran with Python 2.7.5
    ansible_python_interpreter: /usr/bin/python3

Then I did not get the napalm module missing, but this error:

{
"_ansible_no_log": false,
"failed_modules": {
"ios_facts": {
"failed": true,
"exception": "Traceback (most recent call last):\n File "/var/lib/awx/.ansible/tmp/ansible-local-32QVR8K/ansible-tmp-1621697468.49-13-199521279718636/AnsiballZ_ios_facts.py", line 102, in \n _ansiballz_main()\n File "/var/lib/awx/.ansible/tmp/ansible-local-32QVR8K/ansible-tmp-1621697468.49-13-199521279718636/AnsiballZ_ios_facts.py", line 17, in _ansiballz_main\n import base64\n File "/usr/lib64/python3.6/base64.py", line 9, in \n import re\n File "/usr/lib64/python3.6/re.py", line 142, in \n class RegexFlag(enum.IntFlag):\nAttributeError: module 'enum' has no attribute 'IntFlag'\n",
"rc": 1,
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"module_stderr": "Traceback (most recent call last):\n File "/var/lib/awx/.ansible/tmp/ansible-local-32QVR8K/ansible-tmp-1621697468.49-13-199521279718636/AnsiballZ_ios_facts.py", line 102, in \n _ansiballz_main()\n File "/var/lib/awx/.ansible/tmp/ansible-local-32QVR8K/ansible-tmp-1621697468.49-13-199521279718636/AnsiballZ_ios_facts.py", line 17, in _ansiballz_main\n import base64\n File "/usr/lib64/python3.6/base64.py", line 9, in \n import re\n File "/usr/lib64/python3.6/re.py", line 142, in \n class RegexFlag(enum.IntFlag):\nAttributeError: module 'enum' has no attribute 'IntFlag'\n",
"module_stdout": ""
}
},
"msg": "The following modules failed to execute: ios_facts\n",
"changed": false,
"_ansible_verbose_override": true,
"ansible_facts": {}
}

Any ideas? This playbook runs on command line Ansible

It actually had to do with me installing napalm as root. It seemed to have broken Tower as well.

It's just a VM so I am starting over with CentOS 8 to get rid of Python 2/3 issues as well.

https://docs.ansible.com/ansible-tower/latest/html/upgrade-migration-guide/virtualenv.html

I keep you posted the final outcome since I think this will help others using Tower and napalm

This worked with venv, to recap:

"Ansible Tower creates two virtualenvs during installation–one is used to run Tower, while the other is used to run Ansible. This allows Tower to run in a stable environment, while allowing you to add or update modules to your Ansible Python environment as necessary to run your playbooks."

[centos@localhost ~]$ cd /var/lib/awx/venv
[centos@localhost venv]$ source ansible/bin/activate
(ansible) [centos@localhost venv]$ sudo pip3 install --upgrade pip
(ansible) [centos@localhost venv]$ sudo pip3 install napalm

This produced an error with pyYAML package, so I followed these instructions:
https://stackoverflow.com/questions/49911550/how-to-upgrade-disutils-package-pyyaml
sudo -H pip3 install --ignore-installed PyYAML

All good now on Tower.

Kirk thanks for all the help and the amazing amount of effort you put into napalm.