Juniper / ansible-junos-stdlib

Junos modules for Ansible
Apache License 2.0
306 stars 158 forks source link

Juniper.junos role is not honoring the ANSIBLE_NET_USERNAME/PASSWORD environment variables set inside the playbook #399

Closed Involar closed 3 years ago

Involar commented 6 years ago

Issue Type

Module Name

juniper_junos_config

ansible 2.6.0
  config file = /var/lib/rundeck/.ansible.cfg
  configured module search path = ['/var/lib/rundeck/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.2 (default, Aug  2 2017, 09:56:55) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]

- Juniper.junos, 2.1.0

OS / Environment

Ansible server: CentOS release 6.9 Junos: 15.1F6-S7.2 Device: mx480

Summary

Steps to reproduce

The juniper.junos role does not recognize environment variables set within a playbook. You can't set a username or password from a playbook to be used for authentication.

playbook:
- name: "Test"
  hosts: localhost
  vars_files:
    - env_file.yml
  roles:
    - role: Juniper.junos
  environment:
    "{{ env_vars }}"
  connection: local
  gather_facts: no

  tasks:
    - name: "test"
      juniper_junos_config:
       load: "merge"
       config_mode: "private"
       check: "{{ check }}"
       commit: "{{ commit }}"
       template: "template.j2"
       format: "text"
       vars:
         interface: "{{ interface }}"
       provider:
         host: "{{ ansible_host }}"
         timeout: 180
      register: response

env_file:
env_vars:
  ANSIBLE_NET_USERNAME: 'username'
  ANSIBLE_NET_PASSWORD: 'password'

Expected results

Username/password variable within the provider dictionary to be set to the value contained in ANSIBLE_NET_.......

Actual results

The variable user is unchanged. According to the priority list for user it picks the Environmental variable USER which is set to the user running the playbook.

I have tested this with a simple task using shell: echo $ANSIBLE_NET_USERNAME and it returns the correct value which i'm providing inside my environment file.

TASK [Test] ******************************************************************************************************************************************************
task path: /data/rundeck/juniper_provision/file1.yaml:44
Using module file /etc/ansible/roles/Juniper.junos/library/juniper_junos_config.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: rundeck
<127.0.0.1> EXEC /bin/sh -c '/usr/local/bin/python3.6 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "attempts": null,
            "baud": null,
            "check": true,
            "check_commit_wait": null,
            "comment": null,
            "commit": false,
            "commit_empty_changes": false,
            "config_mode": "private",
            "confirmed": null,
            "console": null,
            "dest": null,
            "dest_dir": null,
            "diff": null,
            "diffs_file": null,
            "filter": null,
            "format": "text",
            "host": "router",
            "ignore_warning": null,
            "level": null,
            "lines": null,
            "load": "merge",
            "logdir": null,
            "logfile": null,
            "mode": null,
            "options": {},
            "passwd": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 830,
            "retrieve": null,
            "return_output": true,
            "rollback": null,
            "src": null,
            "ssh_config": null,
            "ssh_private_key_file": null,
            "template": "template.j2",
            "timeout": 180,
            "url": null,
            "user": "rundeck",
            "vars": {
                "interface": "ge-5/0/1"
            }
        }
    },
    "msg": "missing required arguments: user"
}

PLAY RECAP ********************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1
vnitinv commented 6 years ago

@Involar Thanks for reporting. @rsmekala Can you please check this?

Involar commented 6 years ago

A workaround that I found is to "gather_facts" and then use the presented ansible_env var as an argument for user/passwd variables. I have a feeling this is a bug in Ansible, rather than in the role.

       provider:
         host: "{{ ansible_host }}"
         timeout: 180
         user: "{{ ansible_env.ANSIBLE_NET_USERNAME}}"
         passwd: "{{ ansible_env.ANSIBLE_NET_PASSWORD}}"
rahkumar651991 commented 3 years ago

based on the discussion, marking this as inactive.