ansible-junos-stdlib icon indicating copy to clipboard operation
ansible-junos-stdlib copied to clipboard

run juniper_junos_jsnapy module with telnet mode is error

Open tuhoanganh opened this issue 4 years ago • 0 comments

Issue Type

  • Bug Report

Module Name

juniper_junos_jsnapy

juniper.device collection and Python libraries version

- ansible --version
ansible 2.8.0
  config file = /opt/SVTECH-Junos-Automation/Ansible-Development/ansible.cfg
  configured module search path = ['/opt/SVTECH-Junos-Automation/Ansible-Development/library']
  ansible python module location = /opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/ansible
  executable location = /opt/.pyenv/versions/automation36/bin/ansible
  python version = 3.6.5 (default, Oct  8 2020, 10:56:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

- pip freeze
ansible==2.8.0
bcrypt==3.2.0
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
click==7.1.2
colorama==0.4.3
configparser==5.0.0
cryptography==3.1.1
decorator==4.4.2
docker==4.3.1
easysnmp==0.2.5
english==2020.7.0
et-xmlfile==1.0.1
Flask==1.1.2
future==0.18.2
icdiff==1.9.1
idna==2.10
importlib-resources==3.0.0
influxdb==5.3.0
itsdangerous==1.1.0
jdcal==1.4.1
Jinja2==2.11.2
jmespath==0.10.0
jsnapy==1.3.2
junos-eznc==2.5.3
jxmlease==1.0.3
lxml==4.5.2
MarkupSafe==1.1.1
monotonic==1.5
msgpack==0.6.1
mysql-connector==2.2.9
ncclient==0.6.9
neotime==1.7.4
netaddr==0.8.0
networkx==2.5
ntc-templates==1.6.0
numpy==1.19.2
openpyxl==3.0.5
packaging==20.4
pandas==1.1.3
pansi==2020.7.3
paramiko==2.7.2
ply==3.11
prompt-toolkit==2.0.10
py2neo==2020.0.0
pyasn1==0.4.8
pycparser==2.20
pycryptodomex==3.9.8
pydot==1.4.1
Pygments==2.7.1
PyMySQL==0.10.1
PyNaCl==1.4.0
pyparsing==2.4.7
pyserial==3.4
pysmi==0.3.4
pysnmp==4.4.12
python-dateutil==2.8.1
python3-netsnmp==1.1a1
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
scp==0.13.2
six==1.15.0
SQLAlchemy==1.3.19
tabulate==0.8.7
textfsm==1.1.0
transitions==0.8.3
ttp==0.5.0
urllib3==1.25.10
wcwidth==0.2.5
websocket-client==0.57.0
Werkzeug==1.0.1
xlrd==1.2.0
yamlordereddictloader==0.4.0
zipp==3.3.0

OS / Environment Ansible Server: Centos 7 minmal 1908 Devices:JUNOS 15.1X54-D37.9 - ACX1000, ACX2100

Summary Run module juniper_junos_snappy with telnet mode is error

Steps to reproduce ansible-playbook -i inventories/ACX_test.yml check_log.yml -vvv (please ignore the inventory file, i added static device's information into module)

---
- name: Gather ge-0/0/0 interface information
  hosts: ACX2100
  connection: local
  gather_facts: no
  vars:
    ansible_python_interpreter: "{{ '/opt/.pyenv/versions/3.6.5/envs/automation36/bin/python' if (venv == True) else '/usr/bin/env python' }}"

  roles:
    - Juniper.junos

  tasks:
    - name: "[SNAPSHOT VERSION - STEP 03] - Checking Snapshot version"
      juniper_junos_jsnapy:
        action: "snapcheck"
        test_files: "/opt/SVTECH-Junos-Automation/Ansible-Development/roles/acx_check_snapshot_version/tmp/10.96.10.1_snapcheck_snapshot_version.yml"
        providers:
          username: "juniper"
          password: "abc@123"
          host: 10.96.10.1
          port: 23
          mode: telnet
          timeout: 3600
        logfile: "/opt/SVTECH-Junos-Automation/Ansible-Development/logs/{{inventory_hostname}}_checklog.log"
      register: snapshot_version_current

Expected results The Jsnappy should work as Netconf mode

Actual results

The playbook throws back error: 'Uncaught exception - please report: stat: path should be string, bytes, os.PathLike or integer, not dict' (please see below)

ansible-playbook 2.8.0
  config file = /opt/SVTECH-Junos-Automation/Ansible-Development/ansible.cfg
  configured module search path = ['/opt/SVTECH-Junos-Automation/Ansible-Development/library']
  ansible python module location = /opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/ansible
  executable location = /opt/.pyenv/versions/automation36/bin/ansible-playbook
  python version = 3.6.5 (default, Oct  8 2020, 10:56:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /opt/SVTECH-Junos-Automation/Ansible-Development/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /opt/SVTECH-Junos-Automation/Ansible-Development/inventories/ACX_test.yml as it did not pass it's verify_file() method
script declined parsing /opt/SVTECH-Junos-Automation/Ansible-Development/inventories/ACX_test.yml as it did not pass it's verify_file() method
Parsed /opt/SVTECH-Junos-Automation/Ansible-Development/inventories/ACX_test.yml inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /opt/SVTECH-Junos-Automation/Ansible-Development/callback/rundeck.py
Loading callback plugin timer of type aggregate, v2.0 from /opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/ansible/plugins/callback/timer.py

PLAYBOOK: check_log.yml *******************************************************************************************************************************************************************************
 [WARNING]: Failure using method (v2_playbook_on_start) in callback plugin (<ansible.plugins.callback.rundeck.CallbackModule object at 0x7f61ea81e4e0>): 'CallbackModule' object has no attribute
'_options'

Callback Exception: 
  File "/opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/ansible/executor/task_queue_manager.py", line 333, in send_callback
    method(*new_args, **kwargs)
   File "/opt/SVTECH-Junos-Automation/Ansible-Development/callback/rundeck.py", line 315, in v2_playbook_on_start
    if self._options is not None:

1 plays in check_log.yml

PLAY [Gather ge-0/0/0 interface information] **********************************************************************************************************************************************************
META: ran handlers

TASK [[SNAPSHOT VERSION - STEP 03] - Checking Snapshot version] ***************************************************************************************************************************************
task path: /opt/SVTECH-Junos-Automation/Ansible-Development/check_log.yml:14
Using module file /opt/SVTECH-Junos-Automation/Ansible-Development/roles/Juniper.junos/library/juniper_junos_jsnapy.py
Pipelining is enabled.
<10.96.10.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.96.10.1> EXEC /bin/sh -c '/opt/.pyenv/versions/3.6.5/envs/automation36/bin/python && sleep 0'
The full traceback is:
  File "/tmp/ansible_juniper_junos_jsnapy_payload_svae2i2t/__main__.py", line 298, in main
    dev=junos_module.dev)
  File "/opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/jnpr/jsnapy/jsnapy.py", line 1011, in snapcheck
    res = self.extract_data(data, file_name, "snapcheck", local=local)
  File "/opt/.pyenv/versions/3.6.5/envs/automation36/lib/python3.6/site-packages/jnpr/jsnapy/jsnapy.py", line 835, in extract_data
    if os.path.isfile(config_data):
  File "/opt/.pyenv/versions/3.6.5/lib/python3.6/genericpath.py", line 30, in isfile
    st = os.stat(path)

fatal: [ACX2100]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "action": "snapcheck",
            "attempts": 10,
            "baud": 9600,
            "config_file": null,
            "console": null,
            "cs_passwd": null,
            "cs_user": null,
            "dir": "/etc/jsnapy/testfiles",
            "host": "10.96.10.1",
            "level": null,
            "logdir": null,
            "logfile": null,
            "mode": "telnet",
            "passwd": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 23,
            "ssh_config": null,
            "ssh_private_key_file": null,
            "test_files": [
                "/opt/SVTECH-Junos-Automation/Ansible-Development/roles/acx_check_snapshot_version/tmp/10.96.10.1_snapcheck_snapshot_version.yml"
            ],
            "timeout": 3600,
            "user": "juniper"
        }
    },
    "msg": "Uncaught exception - please report: stat: path should be string, bytes, os.PathLike or integer, not dict"
}

PLAY RECAP ********************************************************************************************************************************************************************************************
ACX2100                    : ok=0    changed=0    unreachable=0    failed=1   

LIST HOST STATE FOR RUNDECK ***************************************************************************************************************************************************************************
RUNDECK:DATA:HOSTS_OK=""
RUNDECK:DATA:HOSTS_ERROR="ACX2100"
RUNDECK:DATA:HOSTS_IGNORED_ERROR=""

Our case study: We'd like to write a playbook that auto generate credential (using telnet mode or netconf mode) base on specific conditions:

  • Port 22/830 is open => generate credential with netconf mode
  • Port 22/830 is disable, 23 is open => generate credential with telnet mode

tuhoanganh avatar Dec 16 '20 10:12 tuhoanganh