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

junos_config: Fails with FileNotFoundError #55

Closed
gefela opened this issue May 30, 2020 · 18 comments
Closed

junos_config: Fails with FileNotFoundError #55

gefela opened this issue May 30, 2020 · 18 comments
Assignees

Comments

@gefela
Copy link

gefela commented May 30, 2020

SUMMARY

junos_config: junos playbook fails with FileNotFoundError

ISSUE TYPE
  • Bug Report
COMPONENT NAME

junos_config

ANSIBLE VERSION
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
CONFIGURATION
ACTION_WARNINGS(default) = True
AGNOSTIC_BECOME_PROMPT(default) = True
ALLOW_WORLD_READABLE_TMPFILES(default) = False
ANSIBLE_CONNECTION_PATH(default) = None
ANSIBLE_COW_PATH(default) = None
ANSIBLE_COW_SELECTION(default) = default
ANSIBLE_COW_WHITELIST(default) = ['bud-frogs', 'bunny', 'cheese', 'daemon', 'default', 'dragon', 'elephant-in-snake',>
ANSIBLE_FORCE_COLOR(default) = False
ANSIBLE_NOCOLOR(default) = False
ANSIBLE_NOCOWS(default) = False
ANSIBLE_PIPELINING(default) = False
ANSIBLE_SSH_ARGS(default) = -C -o ControlMaster=auto -o ControlPersist=60s
ANSIBLE_SSH_CONTROL_PATH(default) = None
ANSIBLE_SSH_CONTROL_PATH_DIR(default) = ~/.ansible/cp
ANSIBLE_SSH_EXECUTABLE(default) = ssh
ANSIBLE_SSH_RETRIES(default) = 0
ANY_ERRORS_FATAL(default) = False
BECOME_ALLOW_SAME_USER(default) = False
BECOME_PLUGIN_PATH(default) = ['/root/.ansible/plugins/become', '/usr/share/ansible/plugins/become']
CACHE_PLUGIN(default) = memory
CACHE_PLUGIN_CONNECTION(default) = None
CACHE_PLUGIN_PREFIX(default) = ansible_facts
CACHE_PLUGIN_TIMEOUT(default) = 86400
COLLECTIONS_PATHS(default) = ['/root/.ansible/collections', '/usr/share/ansible/collections']
COLOR_CHANGED(default) = yellow
COLOR_CONSOLE_PROMPT(default) = white
COLOR_DEBUG(default) = dark gray
COLOR_DEPRECATE(default) = purple
COLOR_DIFF_ADD(default) = green
COLOR_DIFF_LINES(default) = cyan
COLOR_DIFF_REMOVE(default) = red
COLOR_ERROR(default) = red
COLOR_HIGHLIGHT(default) = white
COLOR_OK(default) = green
COLOR_SKIP(default) = cyan
COLOR_UNREACHABLE(default) = bright red
COLOR_VERBOSE(default) = blue
COLOR_WARN(default) = bright purple
COMMAND_WARNINGS(default) = True
CONDITIONAL_BARE_VARS(default) = True
CONNECTION_FACTS_MODULES(default) = {'eos': 'eos_facts', 'frr': 'frr_facts', 'ios': 'ios_facts', 'iosxr': 'iosxr_fact>
COVERAGE_REMOTE_OUTPUT(default) = None
COVERAGE_REMOTE_WHITELIST(default) = *
DEFAULT_ACTION_PLUGIN_PATH(default) = ['/root/.ansible/plugins/action', '/usr/share/ansible/plugins/action']
DEFAULT_ALLOW_UNSAFE_LOOKUPS(default) = False
DEFAULT_ASK_PASS(default) = False
DEFAULT_ASK_VAULT_PASS(default) = False
DEFAULT_BECOME(default) = False
DEFAULT_BECOME_ASK_PASS(default) = False
DEFAULT_BECOME_EXE(default) = None
DEFAULT_BECOME_FLAGS(default) = 
DEFAULT_BECOME_METHOD(default) = sudo
DEFAULT_BECOME_USER(default) = root
DEFAULT_CACHE_PLUGIN_PATH(default) = ['/root/.ansible/plugins/cache', '/usr/share/ansible/plugins/cache']
DEFAULT_CALLABLE_WHITELIST(default) = []
DEFAULT_CALLBACK_PLUGIN_PATH(default) = ['/root/.ansible/plugins/callback', '/usr/share/ansible/plugins/callback']
DEFAULT_CALLBACK_WHITELIST(default) = []
DEFAULT_CLICONF_PLUGIN_PATH(default) = ['/root/.ansible/plugins/cliconf', '/usr/share/ansible/plugins/cliconf']
DEFAULT_CONNECTION_PLUGIN_PATH(default) = ['/root/.ansible/plugins/connection', '/usr/share/ansible/plugins/connectio>
DEFAULT_DEBUG(default) = False
DEFAULT_EXECUTABLE(default) = /bin/sh
DEFAULT_FACT_PATH(default) = None
DEFAULT_FILTER_PLUGIN_PATH(default) = ['/root/.ansible/plugins/filter', '/usr/share/ansible/plugins/filter']
DEFAULT_FORCE_HANDLERS(default) = False
DEFAULT_FORKS(default) = 5
DEFAULT_GATHERING(default) = implicit
DEFAULT_GATHER_SUBSET(default) = ['all']
DEFAULT_GATHER_TIMEOUT(default) = 10
DEFAULT_HANDLER_INCLUDES_STATIC(default) = False
DEFAULT_HASH_BEHAVIOUR(default) = replace
DEFAULT_HOST_LIST(default) = ['/etc/ansible/hosts']
DEFAULT_HTTPAPI_PLUGIN_PATH(default) = ['/root/.ansible/plugins/httpapi', '/usr/share/ansible/plugins/httpapi']
DEFAULT_INTERNAL_POLL_INTERVAL(default) = 0.001
DEFAULT_INVENTORY_PLUGIN_PATH(default) = ['/root/.ansible/plugins/inventory', '/usr/share/ansible/plugins/inventory']
DEFAULT_JINJA2_EXTENSIONS(default) = []
DEFAULT_JINJA2_NATIVE(default) = False
DEFAULT_KEEP_REMOTE_FILES(default) = False
DEFAULT_LIBVIRT_LXC_NOSECLABEL(default) = False
DEFAULT_LOAD_CALLBACK_PLUGINS(default) = False
DEFAULT_LOCAL_TMP(default) = /root/.ansible/tmp/ansible-local-981k6lh2qkt
DEFAULT_LOG_FILTER(default) = []
DEFAULT_LOG_PATH(default) = None
DEFAULT_LOOKUP_PLUGIN_PATH(default) = ['/root/.ansible/plugins/lookup', '/usr/share/ansible/plugins/lookup']
DEFAULT_MANAGED_STR(default) = Ansible managed
DEFAULT_MODULE_ARGS(default) = 
DEFAULT_MODULE_COMPRESSION(default) = ZIP_DEFLATED
DEFAULT_MODULE_NAME(default) = command
DEFAULT_MODULE_PATH(default) = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
DEFAULT_MODULE_UTILS_PATH(default) = ['/root/.ansible/plugins/module_utils', '/usr/share/ansible/plugins/module_utils>
DEFAULT_NETCONF_PLUGIN_PATH(default) = ['/root/.ansible/plugins/netconf', '/usr/share/ansible/plugins/netconf']
DEFAULT_NO_LOG(default) = False
DEFAULT_NO_TARGET_SYSLOG(default) = False
DEFAULT_NULL_REPRESENTATION(default) = None
DEFAULT_POLL_INTERVAL(default) = 15
DEFAULT_PRIVATE_KEY_FILE(default) = None
DEFAULT_PRIVATE_ROLE_VARS(default) = False
DEFAULT_REMOTE_PORT(default) = None
DEFAULT_REMOTE_USER(default) = None
DEFAULT_ROLES_PATH(default) = ['/root/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']
DEFAULT_SCP_IF_SSH(default) = smart
DEFAULT_SELINUX_SPECIAL_FS(default) = ['fuse', 'nfs', 'vboxsf', 'ramfs', '9p', 'vfat']
DEFAULT_SFTP_BATCH_MODE(default) = True
DEFAULT_SQUASH_ACTIONS(default) = ['apk', 'apt', 'dnf', 'homebrew', 'openbsd_pkg', 'pacman', 'pip', 'pkgng', 'yum', '>
DEFAULT_SSH_TRANSFER_METHOD(default) = None
DEFAULT_STDOUT_CALLBACK(default) = default
DEFAULT_STRATEGY(default) = linear
DEFAULT_STRATEGY_PLUGIN_PATH(default) = ['/root/.ansible/plugins/strategy', '/usr/share/ansible/plugins/strategy']
DEFAULT_SU(default) = False
DEFAULT_SYSLOG_FACILITY(default) = LOG_USER
DEFAULT_TASK_INCLUDES_STATIC(default) = False
DEFAULT_TERMINAL_PLUGIN_PATH(default) = ['/root/.ansible/plugins/terminal', '/usr/share/ansible/plugins/terminal']
DEFAULT_TEST_PLUGIN_PATH(default) = ['/root/.ansible/plugins/test', '/usr/share/ansible/plugins/test']
DEFAULT_TIMEOUT(default) = 10
DEFAULT_TRANSPORT(default) = smart
DEFAULT_UNDEFINED_VAR_BEHAVIOR(default) = True
DEFAULT_VARS_PLUGIN_PATH(default) = ['/root/.ansible/plugins/vars', '/usr/share/ansible/plugins/vars']
DEFAULT_VAULT_ENCRYPT_IDENTITY(default) = None
DEFAULT_VAULT_IDENTITY(default) = default
DEFAULT_VAULT_IDENTITY_LIST(default) = []
DEFAULT_VAULT_ID_MATCH(default) = False
DEFAULT_VAULT_PASSWORD_FILE(default) = None
DEFAULT_VERBOSITY(default) = 0
DEPRECATION_WARNINGS(default) = True
DIFF_ALWAYS(default) = False
DIFF_CONTEXT(default) = 3
DISPLAY_ARGS_TO_STDOUT(default) = False
DISPLAY_SKIPPED_HOSTS(default) = True
DOCSITE_ROOT_URL(default) = https://docs.ansible.com/ansible/
DOC_FRAGMENT_PLUGIN_PATH(default) = ['/root/.ansible/plugins/doc_fragments', '/usr/share/ansible/plugins/doc_fragment>
DUPLICATE_YAML_DICT_KEY(default) = warn
ENABLE_TASK_DEBUGGER(default) = False
ERROR_ON_MISSING_HANDLER(default) = True
FACTS_MODULES(default) = ['smart']
GALAXY_IGNORE_CERTS(default) = False
GALAXY_ROLE_SKELETON(default) = None
GALAXY_ROLE_SKELETON_IGNORE(default) = ['^.git$', '^.*/.git_keep$']
GALAXY_SERVER(default) = https://galaxy.ansible.com
GALAXY_SERVER_LIST(default) = None
GALAXY_TOKEN(default) = None
GALAXY_TOKEN_PATH(default) = /root/.ansible/galaxy_token
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
HOST_PATTERN_MISMATCH(default) = warning
INJECT_FACTS_AS_VARS(default) = True
INTERPRETER_PYTHON(default) = auto_legacy
INTERPRETER_PYTHON_DISTRO_MAP(default) = {'centos': {'6': '/usr/bin/python', '8': '/usr/libexec/platform-python'}, 'f>
INTERPRETER_PYTHON_FALLBACK(default) = ['/usr/bin/python', 'python3.7', 'python3.6', 'python3.5', 'python2.7', 'pytho>
INVALID_TASK_ATTRIBUTE_FAILED(default) = True
INVENTORY_ANY_UNPARSED_IS_FAILED(default) = False
INVENTORY_CACHE_ENABLED(default) = False
INVENTORY_CACHE_PLUGIN(default) = None
INVENTORY_CACHE_PLUGIN_CONNECTION(default) = None
INVENTORY_CACHE_PLUGIN_PREFIX(default) = ansible_facts
INVENTORY_CACHE_TIMEOUT(default) = 3600
INVENTORY_ENABLED(default) = ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml']
INVENTORY_EXPORT(default) = False
INVENTORY_IGNORE_EXTS(default) = {{(BLACKLIST_EXTS + ( '.orig', '.ini', '.cfg', '.retry'))}}
INVENTORY_IGNORE_PATTERNS(default) = []
INVENTORY_UNPARSED_IS_FAILED(default) = False
LOCALHOST_WARNING(default) = True
MAX_FILE_SIZE_FOR_DIFF(default) = 104448
NETCONF_SSH_CONFIG(default) = None
NETWORK_GROUP_MODULES(default) = ['eos', 'nxos', 'ios', 'iosxr', 'junos', 'enos', 'ce', 'vyos', 'sros', 'dellos9', 'd>
OLD_PLUGIN_CACHE_CLEARING(default) = False
PARAMIKO_HOST_KEY_AUTO_ADD(default) = False
PARAMIKO_LOOK_FOR_KEYS(default) = True
PERSISTENT_COMMAND_TIMEOUT(default) = 30
PERSISTENT_CONNECT_RETRY_TIMEOUT(default) = 15
PERSISTENT_CONNECT_TIMEOUT(default) = 30
PERSISTENT_CONTROL_PATH_DIR(default) = /root/.ansible/pc
PLAYBOOK_DIR(default) = None
PLAYBOOK_VARS_ROOT(default) = top
PLUGIN_FILTERS_CFG(default) = None
PYTHON_MODULE_RLIMIT_NOFILE(default) = 0
RETRY_FILES_ENABLED(default) = False
RETRY_FILES_SAVE_PATH(default) = None
SHOW_CUSTOM_STATS(default) = False
STRING_CONVERSION_ACTION(default) = warn
STRING_TYPE_FILTERS(default) = ['string', 'to_json', 'to_nice_json', 'to_yaml', 'ppretty', 'json']
SYSTEM_WARNINGS(default) = True
TAGS_RUN(default) = []
TAGS_SKIP(default) = []
TASK_DEBUGGER_IGNORE_ERRORS(default) = True
TRANSFORM_INVALID_GROUP_CHARS(default) = never
USE_PERSISTENT_CONNECTIONS(default) = False
VARIABLE_PRECEDENCE(default) = ['all_inventory', 'groups_inventory', 'all_plugins_inventory', 'all_plugins_play', 'gr>
VERBOSE_TO_STDERR(default) = False
YAML_FILENAME_EXTENSIONS(default) = ['.yml', '.yaml', '.json']
OS / ENVIRONMENT
OS = Redhat v 8.1

Target OS = 
Hostname: dmz-firewall
Model: vSRX
Junos: 19.2R1-S2.2
JUNOS OS Kernel 64-bit XEN [20191120.0ebd4bf_builder_stable_11]
JUNOS OS libs [20191120.0ebd4bf_builder_stable_11]
JUNOS OS runtime [20191120.0ebd4bf_builder_stable_11]
JUNOS OS time zone information [20191120.0ebd4bf_builder_stable_11]
JUNOS OS libs compat32 [20191120.0ebd4bf_builder_stable_11]
JUNOS OS 32-bit compatibility [20191120.0ebd4bf_builder_stable_11]
JUNOS py extensions [20191121.175308_builder_junos_192_r1_s2]
JUNOS py base [20191121.175308_builder_junos_192_r1_s2]
JUNOS OS vmguest [20191120.0ebd4bf_builder_stable_11]
JUNOS OS support utilities [20191120.0ebd4bf_builder_stable_11]
JUNOS OS crypto [20191120.0ebd4bf_builder_stable_11]
JUNOS network stack and utilities [20191121.175308_builder_junos_192_r1_s2]
JUNOS libs [20191121.175308_builder_junos_192_r1_s2]
JUNOS libs compat32 [20191121.175308_builder_junos_192_r1_s2]
JUNOS runtime [20191121.175308_builder_junos_192_r1_s2]
JUNOS na telemetry [19.2R1-S2.2]
JUNOS Web Management Platform Package [20191121.175308_builder_junos_192_r1_s2]
JUNOS vsrx modules [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx libs compat32 [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx runtime [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx platform support [20191121.175308_builder_junos_192_r1_s2]
JUNOS common platform support [20191121.175308_builder_junos_192_r1_s2]
JUNOS vsrx runtime [20191121.175308_builder_junos_192_r1_s2]
JUNOS pppoe [20191121.175308_builder_junos_192_r1_s2]
JUNOS Openconfig [19.2R1-S2.2]
JUNOS mtx network modules [20191121.175308_builder_junos_192_r1_s2]
JUNOS modules [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx libs [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx Data Plane Crypto Support [20191121.175308_builder_junos_192_r1_s2]
JUNOS daemons [20191121.175308_builder_junos_192_r1_s2]
JUNOS srx daemons [20191121.175308_builder_junos_192_r1_s2]
JUNOS SRX TVP AppQos Daemon [20191121.175308_builder_junos_192_r1_s2]
JUNOS Extension Toolkit [20191121.175308_builder_junos_192_r1_s2]
JUNOS Juniper Malware Removal Tool (JMRT) [1.0.0+20191121.175308_builder_junos_192_r1_s2]
JUNOS J-Insight [20191121.175308_builder_junos_192_r1_s2]
JUNOS Online Documentation [20191121.175308_builder_junos_192_r1_s2]
JUNOS jail runtime [20191120.0ebd4bf_builder_stable_11]
JUNOS FIPS mode utilities [20191121.175308_builder_junos_192_r1_s2]
STEPS TO REPRODUCE
[juniper]
172.16.203.121

[juniper:vars]
ansible_user=root
ansible_network_os=junos
ansible_connection=netconf
ansible_ssh_private_key_file=~/.ssh/id_rsa
#ansible_become_method=enable
#ansible_become_password=Redhat123
- name: Juniper SRX configuration compliance checks 
  hosts: juniper
  gather_facts: false
  connection: local
  tasks:
  - set_fact:   
      config_directory: '{{ "/home/gefela/ansible_junos/files" | expanduser }}'
  - name: Syslog server check
    junos_config:
      src: '{{ config_directory }}/syslog_config.txt'
      comment: Ensure that appropriate Syslog server configured 
    register: junos_output
  - debug:
       var: junos_output
      
  - name: success
    debug:
      msg: Syslog server check - This check has passed with the following output({{ junos_output }})
    when: not junos_output.changed 
   
  - name: failed
    debug:
      msg: Syslog server check - This check has failed with the following output({{ junos_output }})
    when: junos_output.changed 
  
    
  - name: Admin credentials check
    junos_config:
      src: '{{ config_directory }}/admin_user.txt'
      comment: Ensure that Admin user havee been created
    register: junos_output
  - debug:
       var: junos_output
      
  - name: success
    debug:
      msg: Admin credentials check - This check has passed with the following output({{ junos_output }})
    when: not junos_output.changed 
   
  - name: failed
    debug:
      msg: Admin credentials check - This check has failed with the following output({{ junos_output }})
    when: junos_output.changed 
      
    
  - name: NTP Server check 
    junos_config:
      src: '{{ config_directory }}/NTP_server.txt'
      comment: Ensure that correct NTP servers has been configured
    register: junos_output
  - debug:
       var: junos_output
      
  - name: success
    debug:
      msg: NTP Server check  - This check has passed with the following output({{ junos_output }})
    when: not junos_output.changed 
   
  - name: failed
    debug:
      msg: NTP Server check  - This check has failed with the following output({{ junos_output }})
    when: junos_output.changed 
      
      
  - name: Idle timeout check 
    junos_config:
      src: '{{ config_directory }}/idle_timeout.txt'
      comment: Ensure that idle timeout has been configured 
    register: junos_output
  - debug:
       var: junos_output
      
  - name: success
    debug:
      msg: Idle timeout check   - This check has passed with the following output({{ junos_output
}})
    when: not junos_output.changed 
   
  - name: failed
    debug:
      msg: Idle timeout check   - This check has failed with the following output({{ junos_output }})
    when: junos_output.changed 
EXPECTED RESULTS

The results should be as a resultof comparing the src directory against the configuration of juniper vsrx ... The src files are similar to these
https://github.com/gefela/ansible_junos/tree/master/files

ACTUAL RESULTS

When I run this command .

ansible-playbook -i inventory junos_config_new.yml --check -vvv

I get the following error message .

ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
script declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
auto declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
Parsed /home/gefela/ansible_junos/inventory inventory source with ini plugin

PLAYBOOK: junos_config_new.yml ***************************************************************************************
1 plays in junos_config_new.yml

PLAY [Juniper SRX configuration compliance checks] *******************************************************************
META: ran handlers

TASK [set_fact] ******************************************************************************************************
task path: /home/gefela/ansible_junos/junos_config_new.yml:8
ok: [172.16.203.121] => {
    "ansible_facts": {
        "config_directory": "/home/gefela/ansible_junos/files"
    },
    "changed": false
}

TASK [Syslog server check] *******************************************************************************************
task path: /home/gefela/ansible_junos/junos_config_new.yml:10
<172.16.203.121> ESTABLISH LOCAL CONNECTION FOR USER: gefela
<172.16.203.121> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-2031lj2s5zgq `"&& mkdir /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335 && echo ansible-tmp-1590843912.4412684-2055-226301185204335="` echo /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335 `" ) && sleep 0'
<172.16.203.121> Attempting python interpreter discovery
<172.16.203.121> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<172.16.203.121> Python interpreter discovery fallback (pipelining support required for extended interpreter discovery)
Using module file /root/.local/lib/python3.6/site-packages/ansible/modules/network/junos/junos_config.py
<172.16.203.121> PUT /root/.ansible/tmp/ansible-local-2031lj2s5zgq/tmp18j_fyh_ TO /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335/AnsiballZ_junos_config.py
<172.16.203.121> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335/ /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/usr/bin/python3.6 /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-2031lj2s5zgq/ansible-tmp-1590843912.4412684-2055-226301185204335/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Platform linux on host 172.16.203.121 is using the discovered Python interpreter at /usr/bin/python3.6,
but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
fatal: [172.16.203.121]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3.6"
    },
    "changed": false,
    "module_stderr": "",
    "module_stdout": "\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junos_config_payload_v5kb_re0/ansible_junos_config_payload.zip/ansible/module_utils/network/junos/junos.py\\\", line 97, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junos_config_payload_v5kb_re0/ansible_junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"src_format\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null, \"provider\": null, \"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": null}}}\n\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junos_config_payload_v5kb_re0/ansible_junos_config_payload.zip/ansible/module_utils/network/junos/junos.py\\\", line 97, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junos_config_payload_v5kb_re0/ansible_junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"src_format\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null, \"provider\": null, \"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": null}}}\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP ***********************************************************************************************************
172.16.203.121             : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@samdoran
Copy link

samdoran commented Jun 9, 2020

This looks like an issue with the connection setting. The group vars specify ansible_network_os=junos but the play specifies connection: local. Based on the output of the playbook run, it is connecting to your control node, not the remote device.

<172.16.203.121> ESTABLISH LOCAL CONNECTION FOR USER: gefela

Try removing connection: local from the play.

For more help with networking issues, please reach out to the Ansible Networking community: https://github.com/ansible-collections/junipernetworks.junos#contributing-to-this-collection

@gefela
Copy link
Author

gefela commented Jun 9, 2020 via email

@gefela
Copy link
Author

gefela commented Jun 13, 2020

I have left out connection: local from the play. This is the result ..

ansible-playbook -i inventory junos_config_new.yml  --check -vvv 

ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
script declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
auto declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method
Parsed /home/gefela/ansible_junos/inventory inventory source with ini plugin

PLAYBOOK: junos_config_new.yml ******************************************************
1 plays in junos_config_new.yml

PLAY [Juniper SRX configuration compliance checks] **********************************
META: ran handlers

TASK [Syslog server check] **********************************************************
task path: /home/gefela/ansible_junos/junos_config_new.yml:8
<172.16.203.121> ESTABLISH LOCAL CONNECTION FOR USER: gefela
<172.16.203.121> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-10568fs2tZN `"&& mkdir /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555 && echo ansible-tmp-1592053994.6-10585-173519130537555="` echo /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555 `" ) && sleep 0'
<172.16.203.121> Attempting python interpreter discovery
<172.16.203.121> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<172.16.203.121> Python interpreter discovery fallback (pipelining support required for extended interpreter discovery)
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/junos/junos_config.py
<172.16.203.121> PUT /root/.ansible/tmp/ansible-local-10568fs2tZN/tmpaY2Xjs TO /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555/AnsiballZ_junos_config.py
<172.16.203.121> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555/ /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-10568fs2tZN/ansible-tmp-1592053994.6-10585-173519130537555/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Platform linux on host 172.16.203.121 is using the discovered Python
interpreter at /usr/bin/python, but future installation of another Python
interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
for more information.
fatal: [172.16.203.121]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "module_stderr": "", 
    "module_stdout": "\n{\"msg\": \"Failed to import the required Python library (ncclient) on localhost.localdomain's Python /usr/bin/python2. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter: No module named ncclient.operations\", \"failed\": true, \"exception\": \"WARNING: The below traceback may *not* be related to the actual failure.\\n  File \\\"/tmp/ansible_junos_config_payload_DrROhh/ansible_junos_config_payload.zip/ansible/module_utils/network/junos/junos.py\\\", line 97, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junos_config_payload_DrROhh/ansible_junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"comment\": \"Ensure that appropriate Syslog server configured\", \"username\": null, \"provider\": null, \"backup_options\": null, \"rollback\": null, \"timeout\": null, \"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"confirm\": 0, \"lines\": null, \"update\": \"merge\", \"replace\": null, \"confirm_commit\": false, \"host\": null, \"zeroize\": false, \"src_format\": \"set\", \"ssh_keyfile\": null, \"check_commit\": false, \"password\": null, \"backup\": false, \"port\": null, \"transport\": null}}}\n\n{\"msg\": \"Failed to import the required Python library (ncclient) on localhost.localdomain's Python /usr/bin/python2. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter: No module named ncclient.operations\", \"failed\": true, \"exception\": \"WARNING: The below traceback may *not* be related to the actual failure.\\n  File \\\"/tmp/ansible_junos_config_payload_DrROhh/ansible_junos_config_payload.zip/ansible/module_utils/network/junos/junos.py\\\", line 97, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junos_config_payload_DrROhh/ansible_junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"comment\": \"Ensure that appropriate Syslog server configured\", \"username\": null, \"provider\": null, \"backup_options\": null, \"rollback\": null, \"timeout\": null, \"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"confirm\": 0, \"lines\": null, \"update\": \"merge\", \"replace\": null, \"confirm_commit\": false, \"host\": null, \"zeroize\": false, \"src_format\": \"set\", \"ssh_keyfile\": null, \"check_commit\": false, \"password\": null, \"backup\": false, \"port\": null, \"transport\": null}}}\n", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

PLAY RECAP **************************************************************************
172.16.203.121             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@gefela
Copy link
Author

gefela commented Jun 13, 2020

I have also changed this but it does not make any difference
[juniper]
172.16.203.121

[juniper:vars]
ansible_user=auto
ansible_network_os=junos
ansible_connection=local
ansible_ssh_private_key_file=~/.ssh/id_rsa

@pabelanger
Copy link
Contributor

Try using:

ansible_network_os=junipernetworks.junos.junos

in your inventory file

@Qalthos
Copy link
Contributor

Qalthos commented Jun 15, 2020

Moreover, I see

Failed to import the required Python library (ncclient) on localhost.localdomain's Python /usr/bin/python2. Please read module documentation and install in the appropriate location.

Is ncclient installed?

@gefela
Copy link
Author

gefela commented Jun 15, 2020

ncclient is installed .I have also changed this

[juniper]
172.16.203.121

[juniper:vars]
ansible_user=auto
ansible_network_os=junipernetworks.junos.junos
ansible_connection=local

still the same error message

[gefelas@localhost ansible_junos]$ sudo ansible-playbook -i inventory junos_config_new.yml --check -vvv

ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /bin/ansible-playbook
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
script declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
auto declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
Parsed /home/gefelas/ansible_junos/inventory inventory source with ini plugin

PLAYBOOK: junos_config_new.yml *****************************************************************************************************************************
1 plays in junos_config_new.yml

PLAY [Juniper SRX configuration compliance checks] *********************************************************************************************************
META: ran handlers

TASK [set_fact] ********************************************************************************************************************************************
task path: /home/gefelas/ansible_junos/junos_config_new.yml:6
ok: [172.16.203.121] => {
    "ansible_facts": {
        "config_directory": "/home/gefelas/ansible_junos/files/"
    },
    "changed": false
}

TASK [Syslog server check] *********************************************************************************************************************************
task path: /home/gefelas/ansible_junos/junos_config_new.yml:8
<172.16.203.121> using connection plugin netconf (was local)
<172.16.203.121> ESTABLISH LOCAL CONNECTION FOR USER: root
<172.16.203.121> EXEC /bin/sh -c 'echo ~root && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004 && echo ansible-tmp-1592237476.2405064-51284-84838322290004="` echo /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004 `" ) && sleep 0'
<172.16.203.121> Attempting python interpreter discovery
<172.16.203.121> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/bin/python3.6 && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/junipernetworks/junos/plugins/modules/junos_config.py
<172.16.203.121> PUT /root/.ansible/tmp/ansible-local-512740n0h43l6/tmpudyq6zoc TO /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004/AnsiballZ_junos_config.py
<172.16.203.121> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004/ /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/usr/libexec/platform-python /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1592237476.2405064-51284-84838322290004/ > /dev/null 2>&1 && sleep 0'
fatal: [172.16.203.121]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "module_stderr": "",
    "module_stdout": "\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_qxa6jbwf/ansible_junipernetworks.junos.junos_config_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 109, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_qxa6jbwf/ansible_junipernetworks.junos.junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"src_format\": \"set\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": 2.14}]}\n\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_qxa6jbwf/ansible_junipernetworks.junos.junos_config_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 109, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_qxa6jbwf/ansible_junipernetworks.junos.junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"src_format\": \"set\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": 2.14}]}\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *************************************************************************************************************************************************
172.16.203.121             : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@Qalthos
Copy link
Contributor

Qalthos commented Jun 16, 2020

So unfortunately I can't help you with this with the information we have here. There are a number of issues with the logs that I am seeing... running ansible as root being one of them. But more importantly, there is a lack of consistency among the different runs that makes it very hard to draw any conclusions.

There have been three different python interpreters used over the three runs of this playbook. First python3.6, then python (which is really python2.7), and then finally and most bizarrely of all, platform-python, RHEL's internal python interpreter which almost certainly shouldn't be what you're using.

Each run is also using a completely different install of ansible... the second obviously being installed for python2.7, but the first appears to have been installed for the root user, and the last system-wide.

That said, none of this should really matter (except maybe platform-python), but I'm not familiar enough with netconf to know what sort of file issue this might be... it shouldn't be that the file in src can't be found, because that error is already handled. The fact that this fails in get_capabilities() is also interesting, as that would indicate that this is possibly failing during connection.

My suggestion is to delete /tmp/ansible.log, rerun the playbook as your normal user with ANSIBLE_PERSISTENT_LOG_MESSAGES=True ansible-playbook -i inventory junos_config_new.yml --check -vvv and post the log file to a gist or something so we can have a look at what is actually causing this.

@rohitthakur2590
Copy link
Collaborator

@gefela In addition to detailed logs ,Could you show how your syslog_config.txt file looks like.

@gefela
Copy link
Author

gefela commented Jun 17, 2020

@rohitthakur2590 This is the contents of syslog_config.txt

[gefelas@localhost ansible_junos]$ cat files/syslog_config.txt
set system syslog archive size 300000
set system syslog archive files 3
set system syslog archive world-readable
set system syslog user * any emergency
set system syslog host 192.168.100.70 any any
set system syslog host 192.168.100.70 interactive-commands any
set system syslog host 192.168.100.70 facility-override local1
set system syslog host 192.168.100.70 log-prefix firewall
set system syslog host 192.168.100.70 source-address "{{ inventory_hostname }}"
set system syslog host 192.168.100.70 explicit-priority
set system syslog file messages any critical
set system syslog file messages authorization info
set system syslog file default-log-messages structured-data
set system syslog file sessions user info
set system syslog file interactive-commands interactive-commands error

The rest are similar to what is in this repo
https://github.com/gefela/ansible_junos/tree/master/files

@gefela
Copy link
Author

gefela commented Jun 17, 2020

@Qalthos ; I haven't specified the log path in the ansible.cfg file . However I have done this

export ANSIBLE_PERSISTENT_LOG_MESSAGES=True
sudo ansible-playbook -i inventory junos_config_new.yml  --check -vvv

This is the result below
ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /bin/ansible-playbook
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
script declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
auto declined parsing /home/gefelas/ansible_junos/inventory as it did not pass its verify_file() method
Parsed /home/gefelas/ansible_junos/inventory inventory source with ini plugin

PLAYBOOK: junos_config_new.yml *****************************************************************************************************************************
1 plays in junos_config_new.yml

PLAY [Juniper SRX configuration compliance checks] *********************************************************************************************************
META: ran handlers

TASK [set_fact] ********************************************************************************************************************************************
task path: /home/gefelas/ansible_junos/junos_config_new.yml:6
ok: [172.16.203.121] => {
    "ansible_facts": {
        "config_directory": "/home/gefelas/ansible_junos/files/"
    },
    "changed": false
}

TASK [Syslog server check] *********************************************************************************************************************************
task path: /home/gefelas/ansible_junos/junos_config_new.yml:8
<172.16.203.121> using connection plugin netconf (was local)
<172.16.203.121> ESTABLISH LOCAL CONNECTION FOR USER: root
<172.16.203.121> EXEC /bin/sh -c 'echo ~root && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694 && echo ansible-tmp-1592393485.5380602-15153-271993663002694="` echo /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694 `" ) && sleep 0'
<172.16.203.121> Attempting python interpreter discovery
<172.16.203.121> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/bin/python3.6 && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/junipernetworks/junos/plugins/modules/junos_config.py
<172.16.203.121> PUT /root/.ansible/tmp/ansible-local-15143bvm_ueqq/tmpe6g1ksgm TO /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694/AnsiballZ_junos_config.py
<172.16.203.121> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694/ /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c '/usr/libexec/platform-python /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694/AnsiballZ_junos_config.py && sleep 0'
<172.16.203.121> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1592393485.5380602-15153-271993663002694/ > /dev/null 2>&1 && sleep 0'
fatal: [172.16.203.121]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "module_stderr": "",
    "module_stdout": "\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_1bbykalz/ansible_junipernetworks.junos.junos_config_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 109, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_1bbykalz/ansible_junipernetworks.junos.junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"src_format\": \"set\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": 2.14}]}\n\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", \"failed\": true, \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_1bbykalz/ansible_junipernetworks.junos.junos_config_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 109, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_config_payload_1bbykalz/ansible_junipernetworks.junos.junos_config_payload.zip/ansible/module_utils/connection.py\\\", line 185, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"src\": \"set system syslog archive size 300000\\nset system syslog archive files 3\\nset system syslog archive world-readable\\nset system syslog user * any emergency\\nset system syslog host 192.168.100.70 any any\\nset system syslog host 192.168.100.70 interactive-commands any\\nset system syslog host 192.168.100.70 facility-override local1\\nset system syslog host 192.168.100.70 log-prefix firewall\\nset system syslog host 192.168.100.70 source-address \\\"172.16.203.121\\\"\\nset system syslog host 192.168.100.70 explicit-priority\\nset system syslog file messages any critical\\nset system syslog file messages authorization info\\nset system syslog file default-log-messages structured-data\\nset system syslog file sessions user info\\nset system syslog file interactive-commands interactive-commands error\\n\", \"src_format\": \"set\", \"comment\": \"Ensure that appropriate Syslog server configured\", \"provider\": {\"host\": null, \"port\": null, \"username\": null, \"password\": null, \"ssh_keyfile\": null, \"timeout\": null, \"transport\": \"netconf\"}, \"update\": \"merge\", \"confirm\": 0, \"confirm_commit\": false, \"check_commit\": false, \"backup\": false, \"zeroize\": false, \"lines\": null, \"replace\": null, \"backup_options\": null, \"rollback\": null}}, \"deprecations\": [{\"msg\": \"Param 'provider' is deprecated. See the module docs for more information\", \"version\": 2.14}]}\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *************************************************************************************************************************************************
172.16.203.121             : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@Qalthos
Copy link
Contributor

Qalthos commented Jun 17, 2020

Sorry, yes you need to set a log path. I had honestly forgotten that wasn't a default. Additionally, you are still using sudo to run ansible-playbook for some reason, which won't be able to pick up the exported var you set. So please run this line exactly as described and link to the generated ansible.log file in a gist or pastebin or similar to avoid drowning this issue in log files.

ANSIBLE_PERSISTENT_LOG_MESSAGES=True ANSIBLE_LOG_PATH=ansible.log ansible-playbook -i inventory junos_config_new.yml --check -vvv

@gefela
Copy link
Author

gefela commented Jun 17, 2020

Here is the output from the command
ANSIBLE_PERSISTENT_LOG_MESSAGES=True ANSIBLE_LOG_PATH=ansible.log ansible-playbook -i inventory junos_config_new.yml --check -vvv

https://pastebin.com/nQcfd3L5

@Qalthos
Copy link
Contributor

Qalthos commented Jun 17, 2020

Alright, now we're getting somewhere. The FileNotFoundError is coming from ncclient's connect() method. The only files that I see being passed in to connect() is private_key_file, which I see you have set to ~/.ssh/id_rsa... but as you are running ansible as root, that would be /root/.ssh/id_rsa... which I am assuming is not what you want.

Indeed, running a similar playbook as root with a private_key_file that doesn't exist gives me the FileNotFoundError as described. I have made a PR in ansible.netcommon that should at least help make the error something actionable, but really the easiest fix is to not run ansible as root!

@gefela
Copy link
Author

gefela commented Jun 18, 2020

I have tried running ansible as a non-root user but it is still the same

@gefela
Copy link
Author

gefela commented Jun 18, 2020

The inventory is now as follows

[juniper]
172.16.203.121

[juniper:vars]
ansible_user=auto
ansible_network_os=junipernetworks.junos.junos
ansible_connection=local

@gefela
Copy link
Author

gefela commented Jun 18, 2020

The error message is a bit different now
module_stdout": "\n{"msg": "No authentication methods available", "failed": true,
https://pastebin.com/22vbLpjD

@gefela
Copy link
Author

gefela commented Jun 18, 2020

manage to resolve using ansible_user and ansible_password properly in inventory
https://pastebin.com/P9JmvwzH

@gefela gefela closed this as completed Jun 18, 2020
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

5 participants