Skip to content

Commit

Permalink
Merge pull request #31 from sean1986/master
Browse files Browse the repository at this point in the history
updated files for AJA 2nd edition
  • Loading branch information
vnitinv authored Aug 28, 2018
2 parents 27da227 + 34d7852 commit 1285e84
Show file tree
Hide file tree
Showing 224 changed files with 3,074 additions and 2,071 deletions.
14 changes: 7 additions & 7 deletions ansible/Automating_Junos_with_Ansible/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
*Day One: Automating Junos with Ansible* is available as a free PDF on [Juniper J-Net](https://www.juniper.net/us/en/training/jnbooks/day-one/automation-series/automating-junos-ansible/); for eBooks get it on [Apple iBooks/iTunes](https://itunes.apple.com/us/book/day-one-automating-junos-with-ansible/id1351397873?mt=11) or on [Amazon for Kindle](https://www.amazon.com/Day-One-Automating-Junos®-Ansible-ebook/dp/B079YZDVYJ). For print books purchase at the [Day One Print Store](http://store.vervante.com/c/v/V4081804173.html).

------------------------------------------------------------

The text of *Day One: Automating Junos with Ansible* walks the reader through creating a number of example playbooks and their supporting files. Some of the playbooks are revised several times in a single chapter. Some of the playbooks are revised several times across several chapters.
The text of *Day One: Automating Junos with Ansible, 2nd Edition* walks the reader through creating a number of example playbooks and their supporting files. Some of the playbooks are revised several times in a single chapter. Some of the playbooks are revised several times across several chapters.

In order to maintain a "flow" the book does not ask the reader to save the revisions to the playbooks and supporting files using different, versioned names (for example, "save playbook-2.yaml as playbook-3.yaml"). Instead, the book assumes the reader will keep revising the files "in place." (This is also, in the author's experience, closer to how scripts and playbooks evolve in the real world.)

However, this lack of versioning creates a problem when trying to represent the files at different states of their evolution, which is the goal of the book's directory in Juniper's GitHub repository. The files in this directory are "versioned" in two ways:

- Playbooks and supporting files from each chapter are in chapter-specific directories. Chapter 8 has two directories because of the changes made to the inventory file during the chapter.

- Some of the playbooks and templates have version suffixes (for example, base-settings-1.yaml, base-settings-2.yaml, etc.) to identify the sequence in which the versions are created in the book.
- Some of the playbooks and templates have version suffixes (for example, base-settings-1.yaml, base-settings-2.yaml, etc.) to identify the sequence in which the versions are created in the book. In most cases, section headers in the book identify the version of the file being worked on in that section.

You can copy each chapter's files and folders, as needed, from the chapter's directory into your ~/aja2 directory if you wish the directory paths to appear as written in the book, or you can run the playbooks for each chapter from within the chapter's directory.

------------------------------------------------------------

You can copy each chapter's files and folders, as needed, into your ~/aja directory if you wish everything to appear exactly as written in the book, or you can run the playbooks for each chapter from within the chapter directory.
*Day One: Automating Junos with Ansible, 2nd Edition* is available as a free PDF on [Juniper J-Net](https://www.juniper.net/us/en/training/jnbooks/day-one/automation-series/automating-junos-ansible/); for eBooks get it on [Apple iBooks/iTunes](https://itunes.apple.com/us/book/day-one-automating-junos-with-ansible/id1351397873?mt=11) or on [Amazon for Kindle](https://www.amazon.com/Day-One-Automating-Junos®-Ansible-ebook/dp/B079YZDVYJ). For print books purchase at the [Day One Print Store](http://store.vervante.com/c/v/V4081804173.html).
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[defaults]
inventory = inventory3
host_key_checking = False
log_path = ~/aja/ansible.log
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,57 @@
vars:
tmp_dir: "tmp"
conf_file: "{{ tmp_dir}}/{{ inventory_hostname }}.conf"
connection_settings:
host: "{{ ansible_host }}"
timeout: 120

tasks:
- name: get device facts
junos_get_facts:
host: "{{ ansible_host }}"
register: jfact

- name: show device facts
debug:
var: jfact
verbosity: 1

- name: confirm or create configs directory
file:
path: "{{ tmp_dir }}"
state: directory
run_once: yes

- name: get device facts
juniper_junos_facts:
provider: "{{ connection_settings }}"

- name: save device information using template
- name: display device facts
debug:
var: junos
verbosity: 1

- name: save device configuration using template
template:
src: template/base-settings-3.j2
dest: "{{ conf_file }}"

- name: install generated configuration file onto device
junos_install_config:
host: "{{ ansible_host }}"
file: "{{ conf_file }}"
timeout: 120
replace: yes
confirm: 10
comment: "playbook base-settings-3.yaml, commit confirmed"
notify: confirm commit

- name: delete generated configuration file
file:
path: "{{ conf_file }}"
state: absent
juniper_junos_config:
provider: "{{ connection_settings }}"
src: "{{ conf_file }}"
load: replace
comment: "playbook base-settings.yaml, commit confirmed"
confirmed: 5
diff: yes
ignore_warning: yes
register: config_results
notify: confirm previous commit

- name: show configuration change
debug:
var: config_results.diff_lines
when: config_results.diff_lines is defined

# - name: delete generated configuration file
# file:
# path: "{{ conf_file }}"
# state: absent

handlers:
- name: confirm commit
junos_commit:
host: "{{ ansible_host }}"
timeout: 120
comment: "playbook base-settings-3.yaml, confirming previous commit"
- name: confirm previous commit
juniper_junos_config:
provider: "{{ connection_settings }}"
comment: "playbook base-settings.yaml, confirming previous commit"
commit: yes
diff: no
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
connection: local
gather_facts: no

vars:
connection_settings:
host: "{{ ansible_host }}"

tasks:
- name: get device facts
junos_get_facts:
host: "{{ ansible_host }}"
juniper_junos_facts:
provider: "{{ connection_settings }}"
register: junos_facts

- name: show device facts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
---
- name: Set up report directory
hosts:
- localhost
connection: local
gather_facts: no

tasks:
- name: generate report directory name
set_fact:
report_dir: "{{ user_data_path }}/reports"

- name: confirm/create report directory
file:
path: "{{ report_dir }}"
state: directory

- name: Get facts from Junos device
hosts:
- all
Expand All @@ -23,18 +7,19 @@
connection: local
gather_facts: no

vars:
connection_settings:
host: "{{ ansible_host }}"

tasks:
- name: get device facts
junos_get_facts:
host: "{{ ansible_host }}"
register: junos_facts
juniper_junos_facts:
provider: "{{ connection_settings }}"

- name: show device facts
- name: show Junos version
debug:
var: junos_facts
verbosity: 1
var: junos.version

- name: save device information using template
template:
src: template/device-facts-2f.j2
dest: "{{ hostvars.localhost.report_dir }}/{{ inventory_hostname }}.txt"
- name: show device uptime
debug:
var: junos.RE0.up_time
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@
---
- name: Set up report directory
hosts:
- localhost
connection: local
gather_facts: no

tasks:
- name: generate report directory name
set_fact:
report_dir: "{{ user_data_path }}/reports"

- name: generate report build directory name
set_fact:
build_dir: "{{ report_dir }}/build"

- name: confirm/create report directory
file:
path: "{{ report_dir }}"
state: directory

- name: delete old report build directory
file:
path: "{{ build_dir }}"
state: absent

- name: confirm/create new report build directory
file:
path: "{{ build_dir }}"
state: directory

- name: Get facts from Junos device
hosts:
- all
Expand All @@ -37,39 +7,20 @@
connection: local
gather_facts: no

tasks:
- name: get device facts
junos_get_facts:
host: "{{ ansible_host }}"
register: junos_facts

- name: show device facts
debug:
var: junos_facts
verbosity: 1

- name: save device information using template
template:
src: template/device-facts-3.j2
dest: "{{ hostvars.localhost.build_dir }}/{{ inventory_hostname }}.txt"

- name: Assemble device report
hosts: localhost
connection: local
gather_facts: yes

vars:
systime: "{{ ansible_date_time.time | replace(':', '-') }}"
timestamp: "{{ ansible_date_time.date }}_{{ systime }}"
report_file: "{{ report_dir }}/device-facts_{{ timestamp }}.csv"
facts_dir: "{{ user_data_path }}/facts"
connection_settings:
host: "{{ ansible_host }}"

tasks:
- name: copy column headers file
copy:
src: template/_device-facts-columns.txt
dest: "{{ build_dir }}/"
- name: confirm/create report directory
file:
path: "{{ facts_dir }}"
state: directory
run_once: yes
delegate_to: localhost

- name: assemble device files into new report
assemble:
src: "{{ build_dir }}"
dest: "{{ report_file }}"
- name: get device facts
juniper_junos_facts:
provider: "{{ connection_settings }}"
savedir: "{{ facts_dir }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
- name: Get facts from Junos device and save as CSV file
hosts:
- all
roles:
- Juniper.junos
connection: local
gather_facts: no

vars:
facts_dir: "{{ user_data_path }}/facts"
facts_build_dir: "{{ user_data_path }}/facts/build"
connection_settings:
host: "{{ ansible_host }}"

tasks:
- name: confirm/create report directory
file:
path: "{{ facts_dir }}"
state: directory
run_once: yes
delegate_to: localhost

- name: confirm/create build directory
file:
path: "{{ facts_build_dir }}"
state: directory
run_once: yes
delegate_to: localhost

- name: get device facts
juniper_junos_facts:
provider: "{{ connection_settings }}"

- name: save device facts
template:
src: template/device-facts-4a.j2
dest: "{{ facts_build_dir }}/{{ inventory_hostname }}.txt"
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
- name: Get facts from Junos device and save as CSV file
hosts:
- all
roles:
- Juniper.junos
connection: local
gather_facts: no

vars:
facts_dir: "{{ user_data_path }}/facts"
facts_build_dir: "{{ user_data_path }}/facts/build"
connection_settings:
host: "{{ ansible_host }}"
systime: "{{ ansible_date_time.time | replace(':', '-') }}"
timestamp: "{{ ansible_date_time.date }}_{{ systime }}"
report_file: "{{ facts_dir }}/device-facts_{{ timestamp }}.csv"

tasks:
- name: get localhost environment info
setup:
run_once: yes
delegate_to: localhost

- name: confirm/create report directory
file:
path: "{{ facts_dir }}"
state: directory
run_once: yes
delegate_to: localhost

- name: delete old build directory if present
file:
path: "{{ facts_build_dir }}"
state: absent
run_once: yes
delegate_to: localhost

- name: create build directory
file:
path: "{{ facts_build_dir }}"
state: directory
run_once: yes
delegate_to: localhost

- name: get device facts
juniper_junos_facts:
provider: "{{ connection_settings }}"

- name: save device facts
template:
src: template/device-facts-5.j2
dest: "{{ facts_build_dir }}/{{ inventory_hostname }}.csv"

- name: assemble inventory report
assemble:
src: "{{ facts_build_dir }}"
dest: "{{ report_file }}"
run_once: yes
delegate_to: localhost
Loading

0 comments on commit 1285e84

Please sign in to comment.