-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4f67ae4
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
language: python | ||
python: | ||
- "2.7" | ||
|
||
# Install python packages for ansible and linters. | ||
install: | ||
- "pip install -r requirements.txt" | ||
|
||
# Execute linting and unit tests before running the main playbook. | ||
before_script: | ||
- "find . -name '*.yml' | xargs yamllint -s" | ||
|
||
# Perform playbook testing with mock CI inputs. | ||
script: | ||
- "ansible-playbook test_playbook.yml -i hosts.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
all: | ||
hosts: | ||
CSR1: | ||
vars: | ||
ansible_network_os: "ios" | ||
ansible_user: "ansible" | ||
ansible_ssh_pass: "ansible" | ||
ntp_server1: "192.0.2.1" | ||
ntp_server2: "192.0.2.2" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
- name: "Manage NTP configuration" | ||
hosts: all | ||
connection: network_cli | ||
gather_facts: false | ||
tasks: | ||
- name: "TASK 1: Validate NTP server IP addresses" | ||
assert: | ||
that: | ||
- "ntp_server1 is defined" | ||
- "ntp_server2 is defined" | ||
- "ntp_server1 | ipv4 == ntp_server1" | ||
- "ntp_server2 | ipv4 == ntp_server2" | ||
msg: "Malformed input; please check ntp_server values" | ||
|
||
- name: "TASK 2: Apply NTP updates" | ||
ios_config: | ||
commands: | ||
- "ntp authenticate" | ||
- "ntp logging" | ||
- "ntp server {{ ntp_server1 }}" | ||
- "ntp server {{ ntp_server2 }}" | ||
register: "ntp_updates" | ||
|
||
- name: "TASK 3: Print changes if NTP config changed" | ||
debug: | ||
var: ntp_updates.updates | ||
when: "ntp_updates.updates is defined" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ansible==2.6.2 | ||
yamllint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
- name: "Import original playbook with modified inputs" | ||
import_playbook: "ntp_playbook.yml" | ||
vars: | ||
ntp_server1: "203.0.113.1" | ||
ntp_server2: "203.0.113.2" | ||
|
||
- name: "Log into routers to test playbook" | ||
hosts: all | ||
connection: network_cli | ||
gather_facts: false | ||
tasks: | ||
- name: "TASK 1: Gather mock NTP data after enabling NTP" | ||
ios_command: | ||
commands: "show ntp associations" | ||
register: ntp_associations | ||
|
||
- name: "TASK 2: Check that mock NTP data is present" | ||
assert: | ||
that: | ||
- "'203.0.113.1' in ntp_associations.stdout[0]" | ||
- "'203.0.113.2' in ntp_associations.stdout[0]" | ||
msg: "Missing some NTP data:\n{{ ntp_associations.stdout[0] }}" | ||
|
||
- name: "TASK 2: Disable NTP" | ||
ios_config: | ||
commands: "no ntp" | ||
|
||
- name: "TASK 3: Wait 2 seconds" | ||
pause: | ||
seconds: 2 | ||
|
||
- name: "TASK 4: Gather mock NTP data after disabling NTP" | ||
ios_command: | ||
commands: "show ntp associations" | ||
register: ntp_associations | ||
|
||
- name: "TASK 5: Check mock NTP data is absent" | ||
assert: | ||
that: | ||
- "'203.0.113.1' not in ntp_associations.stdout[0]" | ||
- "'203.0.113.2' not in ntp_associations.stdout[0]" | ||
msg: "Saw some NTP data:\n{{ ntp_associations.stdout[0] }}" | ||
... |