Comments (5)
Optional args need to be supported by the corresponding napalm drivers. So in order for those to work you'd need to implement them first here.
I am closing this issue as it's not related to napalm-ansible
. Feel free to open a PR in napalm
or open an issue there for discussion.
from napalm-ansible.
This response is a bit confusing as the eos drivers appears to support the optional args parameter unless I am missing something.
So adding this in my playbook...
- name: Load configuration into the device and diff
napalm_install_config:
hostname: "{{ ansible_host }}"
username: fjone
dev_os: "{{ ansible_os_family }}"
optional_args:
commit_session: "{{ ansible_host }}"
commit_pending: True
commit_timer: 00:02:00
commit_comments: "word"
password: test123
config_file: "{{ config_file_name }}"
commit_changeas: True
replace_config: False
get_diffs: False
diff_file: "{{ path }}/{{ hostname }}.conf.diff"
when: has_pending_config == false
tags: [print_action]
Add this to eos.py
` def init(self, hostname, username, password, comments, timeout=60, optional_args=None):
"""Constructor."""
self.device = None
self.hostname = hostname
self.username = username
self.password = password
self.timeout = timeout
self.config_session = None
self.commit_timer = None
self.comments = None
self.locked = False
if optional_args is None:
optional_args = {}
# eos_transport is there for backwards compatibility, transport is the preferred method
self.transport = optional_args.get('transport', optional_args.get('eos_transport', 'https'))
self.config_session = 'napalm_{}'.format(optional_args.get('commit_session', 'Testing Session Commit'))
self.commit_timer = optional_args.get('commit_timer', '00:05:00')
self.comments = optional_args.get('commit_comments', 'Testing comments')
self.commit_pending = optional_args.get('commit_pending', 'Testing comments')`
And it produces null optional_args as displayed above.
So either ansible is passing null to napalm_ansible or na is passing null to eos.py but somewhere optional_args isn't making it to the code I've implemented.
Digging deeper into the code I see in napalm_install_config is instantiating the optional args object to Ansible module
module = AnsibleModule( argument_spec=dict( hostname=dict(type='str', required=False, aliases=['host']), username=dict(type='str', required=False), password=dict(type='str', required=False, no_log=True), provider=dict(type='dict', required=False), timeout=dict(type='int', required=False, default=60), optional_args=dict(required=False, type='dict', default=None), config_file=dict(type='str', required=False), config=dict(type='str', required=False), dev_os=dict(type='str', required=False), commit_changes=dict(type='bool', required=True), replace_config=dict(type='bool', required=False, default=False), diff_file=dict(type='str', required=False, default=None), get_diffs=dict(type='bool', required=False, default=True), archive_file=dict(type='str', required=False, default=None), candidate_file=dict(type='str', required=False, default=None) ), supports_check_mode=True
Then this code digging deep in and instantiating the the network driver object with the eos class.
` if module.params['optional_args'] is None:
optional_args = {}
else:
optional_args = module.params['optional_args']
try:
network_driver = get_network_driver(dev_os)
except ModuleImportError as e:
module.fail_json(msg="Failed to import napalm driver: " + str(e))`
So I added this code to check what this is actually doing...
` #ToDO FWJ_NET_719 I believe variable scope is eating the optional args here
if module.params['optional_args'] is None:
optional_args = {}
save_to_file('No optional args', '/tmp/option_args/no_args.txt')
else:
save_to_file(module.params['optional_args'], '/tmp/option_args/no_args.txt')
optional_args = module.params['optional_args']
save_to_file(optional_args, '/tmp/option_args/no_args.txt')`
And the output of that file is...
[Tue Oct 02 21:53:25] [email protected]:/nae/bin$ cat /tmp/option_args/no_args.txt/nae/bin$ vi ../nae/library/napalm_ansible/modules/napalm_install_config.py
No optional args[Tue Oct 02 21:53:36] [email protected]:
[Tue Oct 02 21:54:56] [email protected]:~/nae/bin$
And the output of that execution is...
fatal: [arista7508e.cvr]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"archive_file": null, "candidate_file": null, "commit_changes": false, "config": null, "config_file": "/aristae.cvr.eos.present.conf", "dev_os": "eos", "diff_file": "/aristae.cvr.eos.present.conf.diff", "get_diffs": true, "hostname": "aristae.cvr.d0cdn.net", "optional_args": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "provider": null, "replace_config": false, "timeout": 60, "username": "fjone"}, "module_name": "napalm_install_config"},
So again even though I have edited the eos.py driver and made my playbook role with the optional_args it is not being passed accordingly so please reopen this issue or advise where I need to go to get this resolved.
from napalm-ansible.
Here is a simple example, I just ran in my lab:
---
- name: Test optional_args
hosts: nxos
tasks:
- name: Verify IP interface
napalm_get_facts:
hostname: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_ssh_pass }}"
dev_os: "nxos"
optional_args:
port: 8443
filter: "interfaces_ip"
Which runs correct and debugging shows this (only included relevant section)
"invocation": {
"module_args": {
"args": null,
"dev_os": "nxos",
"filter": [
"interfaces_ip"
],
"hostname": "nxos1.domain.com",
"ignore_notimplemented": false,
"optional_args": {
"port": 8443
},
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"provider": {
"hostname": "nxos1.domain.com",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"timeout": 60,
"username": "admin"
},
"timeout": 60,
"username": "admin"
}
}
So everything I see indicates that napalm-ansible is running correctly. My guess is that you are doing something wrong on the Ansible side.
from napalm-ansible.
For grins, I added an arbitrary argument to optional_args:
optional_args:
port: 8443
foo: bar
This also showed up in the invocation arguments. This was using Ansible 2.6.5
from napalm-ansible.
@ktbyers That example is on napalm_get_facts, could you show and example a similar output on napalm_install_config and dev_os: eos which is the method routine my issues is occurring on?
from napalm-ansible.
Related Issues (20)
- Can the action_plugin be made to understand ansible_port properly
- New release HOT 4
- Distribute napalm-ansible as a collection HOT 5
- ios.commit_config() error HOT 3
- conform diff format with ansible format
- napalm-ansible ignoring ProxyCommand HOT 2
- Ansible 2.10 breaks build
- napalm-ping was unreliable when testing it for IOS (does default delay_factor need increased)
- Create a napalm rollback module
- Create a commit + confirm module HOT 11
- Convert the tests over to GitHub Actions
- Review documentation and make sure it is updated properly for using the new napalm collection
- Remove old setup.py and other old non-collection code from this repository
- napalm Collection on AWX 19.0.0 HOT 9
- npalm_install_merge.yml does not revert all changes HOT 1
- napalm collection with ansible_network_os fully-qualified HOT 1
- Netmiko4 read_timeout default is too short for IOS commit_conifg operation HOT 29
- napalm_ping: Add source_interface argument
- napalm module : Error: "'ascii' codec can't encode characters in position 5396-5398: ordinal not in range(128)"} HOT 14
- napalm module : Error: "'ascii' codec can't encode characters in position 5396-5398: ordinal not in range(128)"}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from napalm-ansible.