Skip to content

Commit eebc2a6

Browse files
authored
Merge pull request #159 from napalm-automation/develop
napalm-ansible release 1.0.0
2 parents 2afe705 + 853fd94 commit eebc2a6

17 files changed

+114
-79
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ python:
66
- 3.6
77

88
env:
9-
- ANSIBLE_VERSION=2.3
10-
- ANSIBLE_VERSION=2.4
119
- ANSIBLE_VERSION=2.5
1210
- ANSIBLE_VERSION=2.6
11+
- ANSIBLE_VERSION=2.7
12+
- ANSIBLE_VERSION=2.8
1313

1414
install:
1515
- pip install pylama
16-
- pip install napalm
16+
- pip install -r requirements.txt
1717
- pip install "ansible>=$ANSIBLE_VERSION.0,<$ANSIBLE_VERSION.99"
1818
- pip install -r requirements-dev.txt
1919
- pip install -e .

CHANGELOG.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
develop
1+
1.0.0
22
=====
33

4+
- Add support for ansible_network_os
5+
- Fix minor documentation errors
6+
- Expand filenames for `*_file` parameters
7+
- Fix Ansible 2.8 backwards incompatible changes
8+
- Removing support of legacy napalm_base
9+
- Changing napalm_cli to cli_results; napalm_ping to ping_results
10+
- Use yaml safe_load for tests
11+
412
0.10.0
513
=====
614

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Example to get compliance report
105105
validation_file: validate.yml
106106
```
107107

108-
Example to use default connection paramters:
108+
Example to use default connection parameters:
109109
```
110110
- name: get facts from device
111111
napalm_get_facts:

napalm_ansible/modules/napalm_cli.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from __future__ import unicode_literals, print_function
2-
from ansible.module_utils.basic import AnsibleModule, return_values
2+
from ansible.module_utils.basic import AnsibleModule
3+
4+
5+
# FIX for Ansible 2.8 moving this function and making it private
6+
# greatly simplified for napalm-ansible's use
7+
def return_values(obj):
8+
""" Return native stringified values from datastructures.
9+
10+
For use with removing sensitive values pre-jsonification."""
11+
yield str(obj)
312

413

514
DOCUMENTATION = '''
@@ -87,15 +96,6 @@
8796
except ImportError:
8897
pass
8998

90-
# Legacy for pre-reunification napalm (remove in future)
91-
if not napalm_found:
92-
try:
93-
from napalm_base import get_network_driver # noqa
94-
from napalm_base import ModuleImportError # noqa
95-
napalm_found = True
96-
except ImportError:
97-
pass
98-
9999

100100
def main():
101101
module = AnsibleModule(
@@ -175,7 +175,7 @@ def main():
175175
except Exception as e:
176176
module.fail_json(msg="cannot close device connection: " + str(e))
177177

178-
module.exit_json(changed=False, results=cli_response)
178+
module.exit_json(changed=False, cli_results=cli_response)
179179

180180

181181
if __name__ == '__main__':

napalm_ansible/modules/napalm_get_facts.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
This file is part of Ansible
55
6-
Ansible is free software: you can redistribute it and/or modify
7-
it under the terms of the GNU General Public License as published by
6+
Ansible is free software: you can redistribute it and/or modify it
7+
under the terms of the GNU General Public License as published by
88
the Free Software Foundation, either version 3 of the License, or
99
(at your option) any later version.
1010
@@ -17,7 +17,16 @@
1717
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
1818
"""
1919
from __future__ import unicode_literals, print_function
20-
from ansible.module_utils.basic import AnsibleModule, return_values
20+
from ansible.module_utils.basic import AnsibleModule
21+
22+
23+
# FIX for Ansible 2.8 moving this function and making it private
24+
# greatly simplified for napalm-ansible's use
25+
def return_values(obj):
26+
""" Return native stringified values from datastructures.
27+
28+
For use with removing sensitive values pre-jsonification."""
29+
yield str(obj)
2130

2231

2332
DOCUMENTATION = '''
@@ -145,15 +154,6 @@
145154
except ImportError:
146155
pass
147156

148-
# Legacy for pre-reunification napalm (remove in future)
149-
if not napalm_found:
150-
try:
151-
from napalm_base import get_network_driver # noqa
152-
from napalm_base import ModuleImportError # noqa
153-
napalm_found = True
154-
except ImportError:
155-
pass
156-
157157

158158
def main():
159159
module = AnsibleModule(

napalm_ansible/modules/napalm_install_config.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@
1818
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
1919
"""
2020
from __future__ import unicode_literals, print_function
21-
from ansible.module_utils.basic import AnsibleModule, return_values
21+
import os.path
22+
from ansible.module_utils.basic import AnsibleModule
23+
24+
25+
# FIX for Ansible 2.8 moving this function and making it private
26+
# greatly simplified for napalm-ansible's use
27+
def return_values(obj):
28+
""" Return native stringified values from datastructures.
29+
30+
For use with removing sensitive values pre-jsonification."""
31+
yield str(obj)
2232

2333

2434
DOCUMENTATION = '''
@@ -165,15 +175,6 @@
165175
except ImportError:
166176
pass
167177

168-
# Legacy for pre-reunification napalm (remove in future)
169-
if not napalm_found:
170-
try:
171-
from napalm_base import get_network_driver # noqa
172-
from napalm_base import ModuleImportError # noqa
173-
napalm_found = True
174-
except ImportError:
175-
pass
176-
177178

178179
def save_to_file(content, filename):
179180
with open(filename, 'w') as f:
@@ -236,6 +237,14 @@ def main():
236237
get_diffs = module.params['get_diffs']
237238
archive_file = module.params['archive_file']
238239
candidate_file = module.params['candidate_file']
240+
if config_file:
241+
config_file = os.path.expanduser(os.path.expandvars(config_file))
242+
if diff_file:
243+
diff_file = os.path.expanduser(os.path.expandvars(diff_file))
244+
if archive_file:
245+
archive_file = os.path.expanduser(os.path.expandvars(archive_file))
246+
if candidate_file:
247+
candidate_file = os.path.expanduser(os.path.expandvars(candidate_file))
239248

240249
argument_check = {'hostname': hostname, 'username': username, 'dev_os': dev_os}
241250
for key, val in argument_check.items():

napalm_ansible/modules/napalm_parse_yang.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
1818
"""
1919
from __future__ import unicode_literals, print_function
20-
from ansible.module_utils.basic import AnsibleModule, return_values
20+
from ansible.module_utils.basic import AnsibleModule
2121
import json
2222

2323
napalm_found = False
@@ -28,21 +28,21 @@
2828
except ImportError:
2929
pass
3030

31-
# Legacy for pre-reunification napalm (remove in future)
32-
if not napalm_found:
33-
try:
34-
from napalm_base import get_network_driver # noqa
35-
from napalm_base import ModuleImportError # noqa
36-
napalm_found = True
37-
except ImportError:
38-
pass
39-
4031
try:
4132
import napalm_yang
4233
except ImportError:
4334
napalm_yang = None
4435

4536

37+
# FIX for Ansible 2.8 moving this function and making it private
38+
# greatly simplified for napalm-ansible's use
39+
def return_values(obj):
40+
""" Return native stringified values from datastructures.
41+
42+
For use with removing sensitive values pre-jsonification."""
43+
yield str(obj)
44+
45+
4646
DOCUMENTATION = '''
4747
---
4848
module: napalm_parse_yang

napalm_ansible/modules/napalm_ping.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
1515
"""
1616
from __future__ import unicode_literals, print_function
17-
from ansible.module_utils.basic import AnsibleModule, return_values
17+
from ansible.module_utils.basic import AnsibleModule
18+
19+
20+
# FIX for Ansible 2.8 moving this function and making it private
21+
# greatly simplified for napalm-ansible's use
22+
def return_values(obj):
23+
""" Return native stringified values from datastructures.
24+
25+
For use with removing sensitive values pre-jsonification."""
26+
yield str(obj)
1827

1928

2029
DOCUMENTATION = '''
@@ -136,15 +145,6 @@
136145
except ImportError:
137146
pass
138147

139-
# Legacy for pre-reunification napalm (remove in future)
140-
if not napalm_found:
141-
try:
142-
from napalm_base import get_network_driver # noqa
143-
from napalm_base import ModuleImportError # noqa
144-
napalm_found = True
145-
except ImportError:
146-
pass
147-
148148

149149
def main():
150150
module = AnsibleModule(
@@ -236,7 +236,7 @@ def main():
236236
except Exception as e:
237237
module.fail_json(msg="cannot close device connection: " + str(e))
238238

239-
module.exit_json(changed=False, results=ping_response)
239+
module.exit_json(changed=False, ping_results=ping_response)
240240

241241

242242
if __name__ == '__main__':

napalm_ansible/modules/napalm_validate.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import unicode_literals, print_function
2-
from ansible.module_utils.basic import AnsibleModule, return_values
2+
from ansible.module_utils.basic import AnsibleModule
33

44
napalm_found = False
55
try:
@@ -9,21 +9,21 @@
99
except ImportError:
1010
pass
1111

12-
# Legacy for pre-reunification napalm (remove in future)
13-
if not napalm_found:
14-
try:
15-
from napalm_base import get_network_driver # noqa
16-
from napalm_base import ModuleImportError # noqa
17-
napalm_found = True
18-
except ImportError:
19-
pass
20-
2112
try:
2213
import napalm_yang
2314
except ImportError:
2415
napalm_yang = None
2516

2617

18+
# FIX for Ansible 2.8 moving this function and making it private
19+
# greatly simplified for napalm-ansible's use
20+
def return_values(obj):
21+
""" Return native stringified values from datastructures.
22+
23+
For use with removing sensitive values pre-jsonification."""
24+
yield str(obj)
25+
26+
2727
DOCUMENTATION = '''
2828
---
2929
module: napalm_validate

napalm_ansible/plugins/action/napalm.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def run(self, tmp=None, task_vars=None):
1818
# Timeout can't be passed via command-line as Ansible defaults to a 10 second timeout
1919
provider['timeout'] = provider.get('timeout', 60)
2020

21+
if hasattr(pc, 'network_os'):
22+
provider['dev_os'] = provider.get('dev_os', pc.network_os)
23+
2124
self._task.args['provider'] = provider
2225

2326
result = super(ActionModule, self).run(tmp, task_vars)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
napalm
2+
six

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="napalm-ansible",
9-
version='0.10.0',
9+
version='1.0.0',
1010
packages=find_packages(exclude=("test*", "library")),
1111
author="David Barroso, Kirk Byers, Mircea Ulinic",
1212

tests/napalm_cli/multiple_commands.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
register: result
2020
- assert:
2121
that:
22-
- "{{ result.results['show version']|length > 10 }}"
23-
- "{{ result.results['show interfaces']|length > 10 }}"
22+
- "{{ result.cli_results['show version']|length > 10 }}"
23+
- "{{ result.cli_results['show interfaces']|length > 10 }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Get facts
3+
hosts: all
4+
connection: local # code is run locally
5+
gather_facts: no # don't gather facts
6+
tasks:
7+
- block:
8+
- name: get facts from device
9+
napalm_get_facts: # NAPALM plugin
10+
optional_args:
11+
path: "{{ playbook_dir }}/mocked"
12+
profile: "{{ profile }}"
13+
filter: ['facts']

tests/napalm_connection/hosts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[all]
2-
dummy os=mock profile=[eos] password=vagrant
2+
dummy os=mock profile=[eos] password=vagrant ansible_network_os=mock
33

44
[all:vars]
55
ansible_python_interpreter="/usr/bin/env python"

tests/run_tests.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_missing.yaml
55
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_vars.yaml
66
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_args.yaml -u vagrant
7+
ansible-playbook -i napalm_connection/hosts napalm_connection/connection_ansible_network_os.yaml -u vagrant
78
ANSIBLE_REMOTE_USER=vagrant ansible-playbook -i napalm_connection/hosts napalm_connection/connection_info_in_env.yaml
89

910
ansible-playbook -i napalm_install_config/hosts -l "*.dry_run.*" napalm_install_config/config.yaml -C

0 commit comments

Comments
 (0)