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

Add support for passing of command line arguments (in a manner consistent with Ansible core modules) #76

Closed
ktbyers opened this issue Jul 31, 2017 · 5 comments

Comments

@ktbyers
Copy link
Collaborator

ktbyers commented Jul 31, 2017

---
- name: NAPALM on IOS 
  hosts: pynet-rtr1
  tasks:
    - name: NAPALM facts
      napalm_get_facts: 
        hostname: "{{ ansible_host }}"
        dev_os: "ios"
$ ansible-playbook napalm_w_cli.yml -u pyclass -k
SSH password: 

PLAY [NAPALM on IOS] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************
ok: [pynet-rtr1]

TASK [NAPALM facts] **************************************************************************************************************************************************************************************************
fatal: [pynet-rtr1]: FAILED! => {"changed": false, "failed": true, "msg": "username is required"}

PLAY RECAP ***********************************************************************************************************************************************************************************************************
pynet-rtr1                 : ok=1    changed=0    unreachable=0    failed=1   

Also should support if using a provider.

@varnumd
Copy link

varnumd commented Aug 16, 2019

Do you know if this feature was ever introduced - or do you know a good work-around?

@ktbyers
Copy link
Collaborator Author

ktbyers commented Aug 16, 2019

I think that is done.

Let me know if it doesn't work though.

@ktbyers ktbyers closed this as completed Aug 16, 2019
@varnumd
Copy link

varnumd commented Aug 19, 2019

Looks like I have the same error:

(ansible) [14:54:16] dvarnum:ansible-neteng git:(master*) $ ansible-playbook napalm_eos_testing.yml -l lab-campus-leaf3 -u dv -k                      
SSH password: 

PLAY [Get facts] *****************************************************************************************************************************************************************

TASK [get facts from device] *****************************************************************************************************************************************************
fatal: [lab-campus-leaf3]: FAILED! => {"changed": false, "msg": "username is required"}

PLAY RECAP ***********************************************************************************************************************************************************************
lab-campus-leaf3           : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Here's the playbook:

(ansible) [14:59:14] dvarnum:ansible-neteng git:(master*) $ cat napalm_eos_testing.yml
---
- name: Get facts
  hosts: eos
  connection: local
  gather_facts: no

  tasks:
    - name: get facts from device
      napalm_get_facts:
        hostname={{ inventory_hostname }}
        dev_os={{ ansible_network_os }}
        filter='facts,interfaces,bgp_neighbors'
      register: result    

    - name: print data
      debug: var=result

Am I missing something? Thanks for your time!

@ktbyers
Copy link
Collaborator Author

ktbyers commented Oct 11, 2019

Hmmmm, I have to look into the username passing. I could have swore that worked, but I am seeing the same thing as you when I test it.

The -k passing works, but the -u username part is failing.

@ktbyers
Copy link
Collaborator Author

ktbyers commented Oct 11, 2019

This fixes it...not sure why or when this changed though:

$ git diff ./napalm.py
diff --git a/napalm_ansible/plugins/action/napalm.py b/napalm_ansible/plugins/action/napalm.py
index ac37522..bbd70e0 100644
--- a/napalm_ansible/plugins/action/napalm.py
+++ b/napalm_ansible/plugins/action/napalm.py
@@ -13,7 +13,7 @@ class ActionModule(_ActionModule):
             provider = self._task.args.get('provider', {})
 
             provider['hostname'] = provider.get('hostname', provider.get('host', pc.remote_addr))
-            provider['username'] = provider.get('username', pc.connection_user)
+            provider['username'] = provider.get('username', pc.remote_user)
             provider['password'] = provider.get('password', pc.password)
             # Timeout can't be passed via command-line as Ansible defaults to a 10 second timeout
             provider['timeout'] = provider.get('timeout', 60)

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

2 participants