Skip to content

Commit 330ff46

Browse files
author
rsmekala
committed
Merge remote-tracking branch 'upstream/master'
2 parents 9fa1ddc + 79f4713 commit 330ff46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1468
-852
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.travis.yml
2+
ISSUE_TEMPLATE.md
3+
docs/
4+
test/
5+
tools/
6+
COPYRIGHT
7+
env-setup
8+
.vscode

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ desktop.ini
5353

5454
# PyCharm
5555
.idea
56+
57+
# VC Code
58+
.vscode

Dockerfile

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
FROM juniper/pyez:latest
2-
MAINTAINER Stephen Steiner <ssteiner@juniper.net>
32

4-
ARG ver_ansible=2.4.0.0
5-
ARG ver_jsnapy=1.2.1
3+
LABEL net.juniper.image.maintainer="Stephen Steiner <ssteiner@juniper.net>"
64

75
WORKDIR /tmp
8-
RUN mkdir /tmp/ansible-junos-stdlib &&\
9-
mkdir /tmp/ansible-junos-stdlib/library &&\
10-
mkdir /tmp/ansible-junos-stdlib/meta &&\
11-
mkdir /project
12-
13-
ADD action_plugins /tmp/ansible-junos-stdlib/action_plugins
14-
ADD callback_plugins /tmp/ansible-junos-stdlib/callback_plugins
15-
ADD library /tmp/ansible-junos-stdlib/library
16-
ADD LICENSE /tmp/ansible-junos-stdlib/LICENSE
17-
ADD meta /tmp/ansible-junos-stdlib/meta
18-
ADD module_utils /tmp/ansible-junos-stdlib/module_utils
19-
ADD version.py /tmp/ansible-junos-stdlib/version.py
20-
21-
22-
23-
RUN tar -czf Juniper.junos ansible-junos-stdlib &&\
24-
apk update && apk add ca-certificates &&\
25-
apk add openssh-client &&\
26-
apk add build-base gcc g++ make python-dev &&\
27-
apk update && apk add py-pip &&\
28-
pip install --upgrade pip setuptools &&\
29-
pip install jxmlease &&\
30-
pip install ansible==$ver_ansible &&\
31-
pip install jsnapy==$ver_jsnapy &&\
32-
ansible-galaxy install --roles-path=/etc/ansible/roles Juniper.junos &&\
33-
apk del -r --purge gcc make g++ &&\
6+
7+
RUN apk add --no-cache ca-certificates openssh-client build-base gcc g++ make python-dev py-pip
8+
9+
COPY requirements.txt .
10+
RUN pip install -r requirements.txt
11+
12+
RUN apk del -r --purge gcc make g++ &&\
3413
rm -rf /source/* &&\
3514
rm -rf /var/cache/apk/* &&\
3615
rm -rf /tmp/*
3716

38-
WORKDIR /project
17+
WORKDIR /etc/ansible/roles/Juniper.junos
18+
COPY action_plugins action_plugins
19+
COPY callback_plugins callback_plugins
20+
COPY library library
21+
COPY meta meta
22+
COPY module_utils module_utils
23+
24+
WORKDIR /playbooks
25+
26+
VOLUME /playbooks

README.md

Lines changed: 104 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Juniper Ansible roles for Junos
2+
13
## About
24

35
Juniper Networks supports Ansible for managing devices running
@@ -9,6 +11,7 @@ retrieving information, and resetting, rebooting, or shutting down managed devic
911
[INSTALLATION](#installation) section for instructions on installing this role.
1012

1113
## Two Sets of Ansible Modules for Junos devices
14+
1215
Since Ansible version >= 2.1, Ansible also natively includes
1316
[core modules for Junos](http://docs.ansible.com/ansible/list_of_network_modules.html#junos). The Junos modules included
1417
in Ansible core have names which begin with the prefix `junos_`. The Junos modules included in this Juniper.junos role
@@ -17,7 +20,9 @@ Ansible control machine, and an Ansible play may invoke a module from either (or
1720
using the modules in this role when writing new playbooks that manage Junos devices.
1821

1922
## Overview of Modules
23+
2024
This Juniper.junos role includes the following modules:
25+
2126
- **juniper_junos_command** — Execute one or more CLI commands on a Junos device.
2227
- **juniper_junos_config** — Manipulate the configuration of a Junos device.
2328
- **juniper_junos_facts** — Retrieve facts from a Junos device.
@@ -31,6 +36,7 @@ This Juniper.junos role includes the following modules:
3136
- **juniper_junos_table** — Retrieve data from a Junos device using a PyEZ table/view.
3237

3338
### Important Changes
39+
3440
Significant changes to the modules in the Juniper.junos role were made between versions 1.4.3 and 2.0.0.
3541
In versions <= 1.4.3 of the Juniper.junos role, the modules used different module and argument names. Versions >= 2.0.0
3642
of the Juniper.junos role provide backwards compatibility with playbooks written to prior versions of the Juniper.junos
@@ -47,68 +53,75 @@ In addition to the modules listed above, a callback_plugin `jsnapy` is available
4753
The callback_plugin `jsnapy` helps to print on the screen additional information regarding jsnapy failed tests.
4854
For each failed test, a log will be printed after the RECAP of the playbook as shown in this example:
4955

50-
```
51-
PLAY RECAP *********************************************************************
52-
qfx10002-01 : ok=3 changed=0 unreachable=0 failed=1
53-
qfx10002-02 : ok=3 changed=0 unreachable=0 failed=1
54-
qfx5100-01 : ok=1 changed=0 unreachable=0 failed=1
55-
56-
JSNAPy Results for: qfx10002-01 ************************************************
57-
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
58-
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "60021", "peer-state": "Idle", "peer-address": "192.168.0.1"}
59-
Value of 'oper-status' not 'is-equal' at '//interface-information/physical-interface[normalize-space(admin-status)='up' and logical-interface/address-family/address-family-name ]' with {"oper-status": "down", "name": "et-0/0/18"}
60-
61-
JSNAPy Results for: qfx10002-02 ************************************************
62-
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
63-
```
56+
PLAY RECAP *********************************************************************
57+
qfx10002-01 : ok=3 changed=0 unreachable=0 failed=1
58+
qfx10002-02 : ok=3 changed=0 unreachable=0 failed=1
59+
qfx5100-01 : ok=1 changed=0 unreachable=0 failed=1
60+
61+
JSNAPy Results for: qfx10002-01 ************************************************
62+
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
63+
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "60021", "peer-state": "Idle", "peer-address": "192.168.0.1"}
64+
Value of 'oper-status' not 'is-equal' at '//interface-information/physical-interface[normalize-space(admin-status)='up' and logical-interface/address-family/address-family-name ]' with {"oper-status": "down", "name": "et-0/0/18"}
65+
66+
JSNAPy Results for: qfx10002-02 ************************************************
67+
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
6468

6569
The `jsnapy` plugin is currently in **Experimental** stage, please provide feedback.
6670

6771
Callback plugins are not activated by default. They must be manually added to the Ansible
6872
configuration file under the `[defaults]` section using the variable `callback_whitelist`. Specifically, these lines
6973
should be added to the Ansible configuration file in order to allow the jsnapy callback plugin:
70-
```
71-
[defaults]
72-
callback_whitelist = jsnapy
73-
```
74+
75+
[defaults]
76+
callback_whitelist = jsnapy
7477

7578
## DOCUMENTATION
7679

7780
[Official Juniper documentation](http://www.juniper.net/techpubs/en_US/release-independent/junos-ansible/information-products/pathway-pages/index.html) (detailed information, including examples)
7881

7982
[Ansible style documentation](http://junos-ansible-modules.readthedocs.org)
8083

81-
8284
## INSTALLATION
85+
8386
You must have the [DEPENDENCIES](#dependencies) installed on your system.
8487

88+
### NOTICES
89+
90+
#### Ubuntu 14.04
91+
8592
If you're dealing with Ubuntu 14.04 and faced following error during the installation, it's because the system python which used by Ubuntu 14.04 is locked to 2.7.6 till EOL, as a result, please consider to skip galaxy certification process by appending `-c` option of ansible-galaxy. i.e. `ansible-galaxy install Juniper.junos -c`
8693

87-
```
88-
[WARNING]: - Juniper.junos was NOT installed successfully: Failed to get data
89-
from the API server (https://galaxy.ansible.com/api/): Failed to validate the
90-
SSL certificate for galaxy.ansible.com:443. Make sure your managed systems have
91-
a valid CA certificate installed. If the website serving the url uses SNI you
92-
need python >= 2.7.9 on your managed machine (the python executable used
93-
(/usr/bin/python) is version: 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC
94-
4.8.4]) or you can install the `urllib3`, `pyOpenSSL`, `ndg-httpsclient`, and
95-
`pyasn1` python modules to perform SNI verification in python >= 2.6. You can
96-
use validate_certs=False if you do not need to confirm the servers identity but
97-
this is unsafe and not recommended. Paths checked for this platform:
98-
/etc/ssl/certs, /etc/pki/ca-trust/extracted/pem, /etc/pki/tls/certs, /usr/share
99-
/ca-certificates/cacert.org, /etc/ansible. The exception msg was: hostname
100-
u'galaxy.ansible.com' doesn't match either of
101-
'*.c1e4.galaxy.openshiftapps.com', 'c1e4.galaxy.openshiftapps.com'.
102-
103-
ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
104-
```
94+
[WARNING]: - Juniper.junos was NOT installed successfully: Failed to get data
95+
from the API server (https://galaxy.ansible.com/api/): Failed to validate the
96+
SSL certificate for galaxy.ansible.com:443. Make sure your managed systems have
97+
a valid CA certificate installed. If the website serving the url uses SNI you
98+
need python >= 2.7.9 on your managed machine (the python executable used
99+
(/usr/bin/python) is version: 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC
100+
4.8.4]) or you can install the `urllib3`, `pyOpenSSL`, `ndg-httpsclient`, and
101+
`pyasn1` python modules to perform SNI verification in python >= 2.6. You can
102+
use validate_certs=False if you do not need to confirm the servers identity but
103+
this is unsafe and not recommended. Paths checked for this platform:
104+
/etc/ssl/certs, /etc/pki/ca-trust/extracted/pem, /etc/pki/tls/certs, /usr/share
105+
/ca-certificates/cacert.org, /etc/ansible. The exception msg was: hostname
106+
u'galaxy.ansible.com' doesn't match either of
107+
'*.c1e4.galaxy.openshiftapps.com', 'c1e4.galaxy.openshiftapps.com'.
108+
109+
ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
105110

111+
### MacOS Mojave and newer
112+
113+
In MacOS Mojave and newer (>=10.14), ssh keys created with the system `ssh-keygen` are created using the newer 'OPENSSH' key format, even when specifying `-t rsa` during creation. This directly affects the usage of ssh keys, particularly when using the `ssh_private_key_file`. To create/convert/check keys, follow these steps:
114+
115+
- Create a new RSA key: `ssh-keygen -m PEM -t rsa -b 4096`
116+
- Check existing keys: `head -n1 ~/.ssh/some_private_key` RSA keys will be `-----BEGIN RSA PRIVATE KEY-----` and OPENSSH keys will be `-----BEGIN OPENSSH PRIVATE KEY-----`
117+
- Convert an OPENSSH key to an RSA key: `ssh-keygen -p -m PEM -f ~/.ssh/some_key`
106118

107119
### Ansible Galaxy Role
120+
108121
To download the latest released version of the junos role to the Ansible
109122
server, execute the ansible-galaxy install command, and specify **Juniper.junos**.
110123

111-
```
124+
```bash
112125
[root@ansible-cm]# ansible-galaxy install Juniper.junos
113126
- downloading role 'junos', owned by Juniper
114127
- downloading role from https://github.com/Juniper/ansible-junos-stdlib/archive/1.3.1.tar.gz
@@ -118,52 +131,65 @@ server, execute the ansible-galaxy install command, and specify **Juniper.junos*
118131

119132
You can also use the ansible-galaxy install command to install the latest
120133
development version of the junos role directly from GitHub.
121-
```
134+
135+
```bash
122136
sudo ansible-galaxy install git+https://github.com/Juniper/ansible-junos-stdlib.git,,Juniper.junos
123137
```
124138

125139
### Git clone
140+
126141
For testing you can `git clone` this repo and run the `env-setup` script in the repo directory:
127-
```
142+
143+
```bash
128144
user@ansible-junos-stdlib> source env-setup
129145
```
130-
This will set your `$ANSIBLE_LIBRARY` variable to the repo location and the installed Ansible library path. For example:
131-
```
132-
[jeremy@ansible-junos-stdlib]$ echo $ANSIBLE_LIBRARY
146+
147+
This will set your `$ANSIBLE_LIBRARY` variable to the repo location and the installed Ansible library path. For example:
148+
149+
```bash
150+
$ echo $ANSIBLE_LIBRARY
133151
/home/jeremy/Ansible/ansible-junos-stdlib/library:/usr/share/ansible
134152
```
135153

136154
### Docker
137-
To run this as a Docker container, which includes JSNAPy and PyEZ, simply pull it from the Docker hub and run it.
138-
The following will pull the latest image and run it in an interactive ash shell.
139-
```
140-
$ docker run -it --rm juniper/pyez-ansible ash
141-
```
142-
Although, you'll probably want to bind mount a host directory (perhaps the directory containing your playbooks and
143-
associated files). The following will bind mount the current working directory and start the ash shell.
155+
156+
To run this as a Docker container, which includes JSNAPy and PyEZ, simply pull it from the Docker hub and run it. The following will pull the latest image and run it in an interactive ash shell.
157+
158+
```bash
159+
docker run -it --rm juniper/pyez-ansible ash
144160
```
145-
$ docker run -it --rm -v $PWD:/project juniper/pyez-ansible ash
161+
162+
Although, you'll probably want to bind mount a host directory (perhaps the directory containing your playbooks and associated files). The following will bind mount the current working directory and start the ash shell.
163+
164+
```bash
165+
docker run -it --rm -v $PWD:/project juniper/pyez-ansible ash
146166
```
167+
147168
You can also use the container as an executable to run your playbooks. Let's assume we have a typical playbook structure as below:
148-
```
149-
example
150-
|playbook.yml
151-
|hosts
152-
|-vars
153-
|-templates
154-
|-scripts
155-
```
169+
170+
example
171+
|playbook.yml
172+
|hosts
173+
|-vars
174+
|-templates
175+
|-scripts
176+
156177
We can move to the example directory and run the playbook with the following command:
178+
179+
```bash
180+
cd example/
181+
docker run -it --rm -v $PWD:/playbooks juniper/pyez-ansible ansible-playbook -i hosts playbook.yml
157182
```
158-
$ docker run -it --rm -v $PWD:/project juniper/pyez-ansible ansible-playbook -i hosts playbook.yml
159-
```
183+
160184
You may have noticed that the base command is almost always the same. We can also use an alias to save some keystrokes.
161-
```
162-
$ alias pb-ansible="docker run -it --rm -v $PWD:/project juniper/pyez-ansible ansible-playbook"
163-
$ pb-ansible -i hosts playbook.yml
185+
186+
```bash
187+
alias pb-ansible="docker run -it --rm -v $PWD:/project juniper/pyez-ansible ansible-playbook"
188+
pb-ansible -i hosts playbook.yml
164189
```
165190

166191
## Example Playbook
192+
167193
This example outlines how to use Ansible to install or upgrade the software image on a device running Junos OS.
168194

169195
```yaml
@@ -198,21 +224,26 @@ This example outlines how to use Ansible to install or upgrade the software imag
198224
- name: wait_reboot
199225
wait_for: host={{ inventory_hostname }} port=830 timeout={{ wait_time }}
200226
when: not sw.check_mode
201-
```
227+
```
202228
203229
## DEPENDENCIES
230+
204231
This modules requires the following to be installed on the Ansible control machine:
205-
* Python >= 2.7
206-
* [Ansible](http://www.ansible.com) 2.3 or later
207-
* Junos [py-junos-eznc](https://github.com/Juniper/py-junos-eznc) 2.1.7 or later
208-
* [jxmlease](https://github.com/Juniper/jxmlease) 1.0.1 or later
232+
233+
- Python >= 2.7
234+
- [Ansible](http://www.ansible.com) 2.3 or later
235+
- Junos [py-junos-eznc](https://github.com/Juniper/py-junos-eznc) 2.1.7 or later
236+
- [jxmlease](https://github.com/Juniper/jxmlease) 1.0.1 or later
209237
210238
## LICENSE
239+
211240
Apache 2.0
212241
213242
## SUPPORT
243+
214244
Support for this Juniper.junos role is provided by the community and Juniper Networks. If you have an
215245
issue with a module in the Juniper.junos role, you may:
246+
216247
- Open a [GitHub issue](https://github.com/Juniper/ansible-junos-stdlib/issues).
217248
- Post a question on our [Google Group](https://groups.google.com/forum/#!forum/junos-python-ez)
218249
- Email [jnpr-community-netdev@juniper.net](jnpr-community-netdev@juniper.net)
@@ -222,15 +253,13 @@ Support for the Junos modules included in Ansible core is provided by Ansible. I
222253
core module you should open a [Github issue against the Ansible project](https://github.com/ansible/ansible/issues).
223254
224255
## CONTRIBUTORS
256+
225257
Juniper Networks is actively contributing to and maintaining this repo. Please contact
226258
[jnpr-community-netdev@juniper.net](jnpr-community-netdev@juniper.net) for any queries.
227259
228260
*Contributors:*
229-
[Nitin Kumar](https://github.com/vnitinv), [Stacy W Smith](https://github.com/stacywsmith),
230-
[David Gethings](https://github.com/dgjnpr)
231-
232-
* v2.1.0: [Raja Shekar](https://github.com/rsmekala), [Stacy W Smith](https://github.com/stacywsmith)
261+
[Nitin Kumar](https://github.com/vnitinv), [Stacy W Smith](https://github.com/stacywsmith), [Stephen Steiner](https://github.com/ntwrkguru)
233262
234263
*Former Contributors:*
235-
[Jeremy Schulman](https://github.com/jeremyschulman), [Rick Sherman](https://github.com/shermdog),
236-
[Damien Garros](https://github.com/dgarros)
264+
265+
[Jeremy Schulman](https://github.com/jeremyschulman), [Rick Sherman](https://github.com/shermdog), [Damien Garros](https://github.com/dgarros), [David Gethings](https://github.com/dgjnpr)

action_plugins/_junos_cli.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)