Chapter 6 Network Reconnaissance
For diagrams, tables, or exact code formatting, .
JOHN W. CAPOBIANCOPRINTED PAGE 106
line: '{{ item }}'
with_items:
- "#####{{inventory_hostname}}#####"
- "{{ ospfneighbor }}"
check_mode: no
- name: create log file for each devicefile: path=./results/running_config/{{ inventory_hostname }}.txt state=touch
check_mode: no
- name: log to file for individual device
lineinfile:
insertafter: EOF
path: ./results/{{ inventory_hostname }}.txt
line: '{{ item }}'
with_items:
- "#####{{inventory_hostname}}#####"
- "{{ ospfneighbor }}"
check_mode: no
Save the file in VS Code as “ios_command_show_ospf_neighbors.yml”.
Commit it to the branch with a similar comment to “ios_command_ospf_neighbors creation”.
Change to the Linux environment.
git pull
Change to the right working branch.
git checkout
Run the new play by changing to the /playbooks/campus/recon/ folder.
ansible-playbook ios_command_show_ospf_neighbors.yml.
Observe the play:
[automateyournetwork@LINUX]$ ansible-playbook ios_command_show_ospfneighbors.yml
PLAY [CAMPUS-DIST] ***************************************************************
TASK [run show ospf neighbors]********************************************************
ok: [DIST01]
ok: [DIST01]
TASK [set_fact]********************************************************************
ok: [DIST01]
ok: [DIST01]
TASK [create log file for all devices]************************************************
ok: [DIST01]
ok: [DIST01]
TASK [log to file for all devices]***************************************************