diff --git a/README.md b/README.md index eddfe31545a70f8739b3f1e20bf803dd7caeeb27..40a22ed0dbe266755517938b704c294e477be8b2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ This repo holds sample Ansible playbooks for the GÉANT OAV Ansible course. -These mostly consist of vEOS examples but there is a `show_version_juniper` example in `Section1/show_version/`. +These mostly consist of vEOS examples but there is a `show_version_juniper` example in `Section2/playbooks/show_version/`. -Some of the files are accompanied by example output, e.g. `show_version.yaml` produced `show_version.output`. +Some of the files are accompanied by example output, e.g. `show_version.yaml` is accompanied by `show_version.output`. diff --git a/Section1/show_version/ansible.cfg b/Section1/show_version/ansible.cfg deleted file mode 100644 index 5a86c42762bc08e8f4e343807c6ebadba38a66d7..0000000000000000000000000000000000000000 --- a/Section1/show_version/ansible.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[defaults] - -deprecation_warnings=False - -# don't like cows? that's unfortunate. -# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1 -nocows = 1 - -# You can only have one 'stdout' callback type enabled at a time. The default -# is 'default'. The 'yaml' or 'debug' stdout callback plugins are easier to read. -# -stdout_callback = default -#stdout_callback = yaml -#stdout_callback = debug - -inventory = hosts diff --git a/Section2/playbooks/ansible.cfg b/Section2/playbooks/ansible.cfg index 259fbb9efeb0decb66e58347ce58744b56550309..913fbe031a292c2ebd254d7f7381cc9c3bfd14bd 100644 --- a/Section2/playbooks/ansible.cfg +++ b/Section2/playbooks/ansible.cfg @@ -4,6 +4,7 @@ host_key_checking = False stdout_callback = yaml +# Damned cows... nocows = True inventory = hosts diff --git a/Section2/playbooks/real_world_group_var.yaml b/Section2/playbooks/group_vars/all.yaml similarity index 100% rename from Section2/playbooks/real_world_group_var.yaml rename to Section2/playbooks/group_vars/all.yaml diff --git a/Section2/playbooks/real_world_host_var.yaml b/Section2/playbooks/host_vars/devicename.yaml similarity index 100% rename from Section2/playbooks/real_world_host_var.yaml rename to Section2/playbooks/host_vars/devicename.yaml diff --git a/Section2/playbooks/hosts b/Section2/playbooks/hosts index 17b64384e6e97dbd82ad988b0d8cfa3cce12553d..685ec3a222fd696db2024671be9cdef061296d3d 100644 --- a/Section2/playbooks/hosts +++ b/Section2/playbooks/hosts @@ -1,9 +1,16 @@ [all:vars] ansible_user=zork ansible_ssh_pass=swordfish +ansible_host=localhost [veos_hosts] -veos ansible_port=9022 ansible_host=localhost ansible_network_os=eos ansible_connection=network_cli +veos ansible_port=9022 ansible_network_os=eos ansible_connection=network_cli [debian_hosts] -testhost ansible_port=9023 ansible_host=localhost +testhost ansible_port=9024 + +# +# Why different passwords? JunOS is a lot stricter. Good! +# +[junos_hosts] +vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123 diff --git a/Section2/playbooks/hosts_simple b/Section2/playbooks/hosts_simple deleted file mode 100644 index 769e9ad120fdc456ab211e35ee6e99c9840aaee8..0000000000000000000000000000000000000000 --- a/Section2/playbooks/hosts_simple +++ /dev/null @@ -1,3 +0,0 @@ -[guinea_pigs] -veos ansible_connection=ssh ansible_host=localhost ansible_port=9022 ansible_user=zork ansible_ssh_pass=swordfish - diff --git a/Section2/playbooks/ping.output b/Section2/playbooks/ping.output new file mode 100644 index 0000000000000000000000000000000000000000..47501c33cc7cdd6218811fac925df05f3d22c71a --- /dev/null +++ b/Section2/playbooks/ping.output @@ -0,0 +1,19 @@ + +PLAY [A play to run the ping module] ****************************************************************************************************************************************** + +TASK [Gathering Facts] ******************************************************************************************************************************************************** +ok: [testhost] + +TASK [A task to invoke the ping module] *************************************************************************************************************************************** +ok: [testhost] + +TASK [A task to print the output] ********************************************************************************************************************************************* +ok: [testhost] => + ping_results: + changed: false + failed: false + ping: pong + +PLAY RECAP ******************************************************************************************************************************************************************** +testhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + diff --git a/Section2/playbooks/ping.yaml b/Section2/playbooks/ping.yaml index 50a1cbdbf3da1b51d5ff0707c9fcbce3e4906974..f5299fe7075f58801ad2f88cdeefa83ece3c26c6 100644 --- a/Section2/playbooks/ping.yaml +++ b/Section2/playbooks/ping.yaml @@ -1,6 +1,6 @@ --- - name: A play to run the ping module - hosts: testhost + hosts: debian_hosts tasks: - name: A task to invoke the ping module ping: diff --git a/Section2/playbooks/ping_unknown_host.output b/Section2/playbooks/ping_unknown_host.output new file mode 100644 index 0000000000000000000000000000000000000000..545b75a2baf5658eda314545eb5b7e9fa2318829 --- /dev/null +++ b/Section2/playbooks/ping_unknown_host.output @@ -0,0 +1,7 @@ +[WARNING]: Could not match supplied host pattern, ignoring: fakeserver + +PLAY [A play to run the ping module] ********************************************************** +skipping: no hosts matched + +PLAY RECAP ************************************************************************************ + diff --git a/Section2/playbooks/ping_unknown_host.yaml b/Section2/playbooks/ping_unknown_host.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7745dfc002120b61fca2d48e7f427a2a61c2e44c --- /dev/null +++ b/Section2/playbooks/ping_unknown_host.yaml @@ -0,0 +1,9 @@ +--- +- name: A play to run the ping module + hosts: fakeserver + tasks: + - name: A task to invoke the ping module + ping: + register: ping_results + - name: A task to print the output + debug: var=ping_results diff --git a/Section2/playbooks/ping_unreachable_host.output b/Section2/playbooks/ping_unreachable_host.output new file mode 100644 index 0000000000000000000000000000000000000000..76adfee8efdd150baacc84026388792467855484 --- /dev/null +++ b/Section2/playbooks/ping_unreachable_host.output @@ -0,0 +1,11 @@ + +PLAY [A play to run the ping module against an unreachable host] *************** + +TASK [Gathering Facts] ********************************************************* +fatal: [vSRX]: UNREACHABLE! => changed=false + msg: 'Failed to connect to the host via ssh: ssh: connect to host localhost port 9023: Connection refused' + unreachable: true + +PLAY RECAP ********************************************************************* +vSRX : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0 + diff --git a/Section2/playbooks/ping_unreachable_host.yaml b/Section2/playbooks/ping_unreachable_host.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2213e9b3fc37c91b9776c1deab9f28ae9c2e36d5 --- /dev/null +++ b/Section2/playbooks/ping_unreachable_host.yaml @@ -0,0 +1,9 @@ +--- +- name: A play to run the ping module against an unreachable host + hosts: vSRX + tasks: + - name: A task to invoke the ping module + ping: + register: ping_results + - name: A task to print the output + debug: var=ping_results diff --git a/Section2/playbooks/show_version.yaml b/Section2/playbooks/show_version.yaml deleted file mode 100644 index 92d342d3764cb18f411b0da3c6c0ba384a92c595..0000000000000000000000000000000000000000 --- a/Section2/playbooks/show_version.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Check the version of code on all switches - hosts: veos - gather_facts: no # or False - tasks: - - name: Gather version from switches - raw: ‘show version| include Software’ - register: show_version - - - name: Display the version - debug: var=show_version - diff --git a/Section1/show_version/README.md b/Section2/playbooks/show_version/README.md similarity index 83% rename from Section1/show_version/README.md rename to Section2/playbooks/show_version/README.md index 6c53d04f3b8b2cafc2d117f354f669545bd42596..00c41977dc2442a1ddd2f96383a23ad0cd272fd3 100644 --- a/Section1/show_version/README.md +++ b/Section2/playbooks/show_version/README.md @@ -4,19 +4,19 @@ The hosts file in this directory has two hosts defined - one vEOS, one JunOS. ``` [all:vars] -ansible_connection=ssh ansible_user=zork +ansible_ssh_pass=swordfish ansible_host=localhost +ansible_connection=ssh [veos_hosts] -veos ansible_port=9022 ansible_ssh_pass=swordfish +veos ansible_port=9022 # # Why different passwords? JunOS is a lot stricter. Good! # [junos_hosts] -vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123 -``` +vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123``` You will need to replace the host information to match your test/learning environment. @@ -34,4 +34,4 @@ Run ``ansible-playbook -i hosts show_version_and_uptime.yaml`` # Device specific -There are device-specific `show version` playbooks. JunOS in particular paginates its output - so you have to run the command through `no-more` to stop it printing `--More--` and pausing for keyboard input...which since it's hidden by Ansible will never come. +There are device-specific `show version` playbooks. JunOS in particular paginates its output - so you have to run the command through `no-more` to stop it printing `--More--` and pausing for keyboard input. Which - since the prompt is hidden by Ansible - will never come. diff --git a/Section2/playbooks/show_version/ansible.cfg b/Section2/playbooks/show_version/ansible.cfg new file mode 100644 index 0000000000000000000000000000000000000000..08ec8e5cf116823b221d4a869a3458165579edbc --- /dev/null +++ b/Section2/playbooks/show_version/ansible.cfg @@ -0,0 +1,9 @@ +[defaults] + +host_key_checking = False + +#stdout_callback = yaml + +nocows = True + +inventory = hosts diff --git a/Section2/playbooks/show_version/hosts b/Section2/playbooks/show_version/hosts new file mode 100644 index 0000000000000000000000000000000000000000..deffb7fe3364a110c9f99c5386ef9e3d623ae2b4 --- /dev/null +++ b/Section2/playbooks/show_version/hosts @@ -0,0 +1,14 @@ +[all:vars] +ansible_user=zork +ansible_ssh_pass=swordfish +ansible_host=localhost +ansible_connection=ssh + +[veos_hosts] +veos ansible_port=9022 + +# +# Why different passwords? JunOS is a lot stricter. Good! +# +[junos_hosts] +vSRX ansible_port=9023 ansible_ssh_pass=Swordfish123 diff --git a/Section1/show_version/show_all_responses.output b/Section2/playbooks/show_version/show_all_responses.output similarity index 55% rename from Section1/show_version/show_all_responses.output rename to Section2/playbooks/show_version/show_all_responses.output index 81c607e1d67e1ae704e90be1c2aec7445ab54357..39beb98c3da033e7b37c63fbd6719592baed46dd 100644 --- a/Section1/show_version/show_all_responses.output +++ b/Section2/playbooks/show_version/show_all_responses.output @@ -1,10 +1,10 @@ -PLAY [Play 1 - Show the software version on an Arista switch] ***************************************************************************************************** +PLAY [Play 1 - Show the software version on an Arista switch] ****************** -TASK [Task 1.1 - Gather version from switches] ******************************************************************************************************************** +TASK [Task 1.1 - Gather version from switch using the raw module] ************** changed: [veos] -TASK [Task 1.2 - Print output] ************************************************************************************************************************************ +TASK [Task 1.2 - Print version] ************************************************ ok: [veos] => { "showvers": { "changed": true, @@ -21,6 +21,6 @@ ok: [veos] => { } } -PLAY RECAP ******************************************************************************************************************************************************** +PLAY RECAP ********************************************************************* veos : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 diff --git a/Section1/show_version/show_all_responses.yaml b/Section2/playbooks/show_version/show_all_responses.yaml similarity index 93% rename from Section1/show_version/show_all_responses.yaml rename to Section2/playbooks/show_version/show_all_responses.yaml index 4f38ce3070726efca2ab520f08eb8ccb55d30dc0..661f90190feb4b012b76db2999d1838ed060146f 100644 --- a/Section1/show_version/show_all_responses.yaml +++ b/Section2/playbooks/show_version/show_all_responses.yaml @@ -1,7 +1,7 @@ --- - name: Play 1 - Show the software version on an Arista switch hosts: veos_hosts - gather_facts: "no" + gather_facts: no connection: local tasks: - name: Task 1.1 - Gather version from switch using the raw module diff --git a/Section1/show_version/show_version.output b/Section2/playbooks/show_version/show_version.output similarity index 100% rename from Section1/show_version/show_version.output rename to Section2/playbooks/show_version/show_version.output diff --git a/Section1/show_version/show_version.yaml b/Section2/playbooks/show_version/show_version.yaml similarity index 97% rename from Section1/show_version/show_version.yaml rename to Section2/playbooks/show_version/show_version.yaml index 8bfe25c96dd7091878dba32ca01614ee07970bf3..6434f0c4b7e45a66a9bb293adb6bba618bff4ddb 100644 --- a/Section1/show_version/show_version.yaml +++ b/Section2/playbooks/show_version/show_version.yaml @@ -1,7 +1,7 @@ --- - name: Play 1 - Show the software version on an Arista switch hosts: veos_hosts - gather_facts: "no" + gather_facts: no connection: local tasks: - name: Task 1.1 - Gather version from switches using the raw module diff --git a/Section1/show_version/show_version_and_uptime.output b/Section2/playbooks/show_version/show_version_and_uptime.output similarity index 100% rename from Section1/show_version/show_version_and_uptime.output rename to Section2/playbooks/show_version/show_version_and_uptime.output diff --git a/Section1/show_version/show_version_and_uptime.yaml b/Section2/playbooks/show_version/show_version_and_uptime.yaml similarity index 100% rename from Section1/show_version/show_version_and_uptime.yaml rename to Section2/playbooks/show_version/show_version_and_uptime.yaml diff --git a/Section1/show_version/show_version_arista.output b/Section2/playbooks/show_version/show_version_arista.output similarity index 100% rename from Section1/show_version/show_version_arista.output rename to Section2/playbooks/show_version/show_version_arista.output diff --git a/Section1/show_version/show_version_arista.yaml b/Section2/playbooks/show_version/show_version_arista.yaml similarity index 97% rename from Section1/show_version/show_version_arista.yaml rename to Section2/playbooks/show_version/show_version_arista.yaml index b7495863238e7c5814eb30d1cd60751b38fa51ea..64cd46fd87dcf14478485fe7bce13725d59c0481 100644 --- a/Section1/show_version/show_version_arista.yaml +++ b/Section2/playbooks/show_version/show_version_arista.yaml @@ -1,7 +1,7 @@ --- - name: Play 1 - Show the software version on an Arista switch hosts: veos_hosts - gather_facts: "no" + gather_facts: no connection: local tasks: - name: Task 1.1 - Gather version from switches diff --git a/Section1/show_version/show_version_juniper.output b/Section2/playbooks/show_version/show_version_juniper.output similarity index 100% rename from Section1/show_version/show_version_juniper.output rename to Section2/playbooks/show_version/show_version_juniper.output diff --git a/Section1/show_version/show_version_juniper.yaml b/Section2/playbooks/show_version/show_version_juniper.yaml similarity index 93% rename from Section1/show_version/show_version_juniper.yaml rename to Section2/playbooks/show_version/show_version_juniper.yaml index cd91f7102b14390250cb4794018aecbefaae2bf2..01b81808cdb0d84c39a97aa8c07c74defe6f252f 100644 --- a/Section1/show_version/show_version_juniper.yaml +++ b/Section2/playbooks/show_version/show_version_juniper.yaml @@ -1,7 +1,7 @@ --- - name: Play 1 - Show the software version on a vSRX hosts: vSRX - gather_facts: "no" + gather_facts: no connection: local tasks: - name: Task 1.1 - Gather version from switches diff --git a/Section2/playbooks/show_version_simple.yaml b/Section2/playbooks/show_version_simple.yaml deleted file mode 100644 index db4625462a91c736b614bf07fabf7d2f02d1be86..0000000000000000000000000000000000000000 --- a/Section2/playbooks/show_version_simple.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- name: Play 1 - Show the software version on an Arista switch - hosts: veos - gather_facts: "no" - connection: local - tasks: - - name: Task 1.1 - Gather version from switches - raw: 'show version | include Software' - register: showvers - - - name: Task 1.2 - Print output - debug: var=showvers.stdout_lines[0] - -- name: Play 2 - Verify switch software - hosts: veos - vars: - eos_version: "4.25" - gather_facts: "no" - connection: local - - tasks: - - name: Task 2.1 - Assert we are running the correct EOS version ({{eos_version}}) - assert: - that: - - "'{{eos_version}}' in showvers.stdout_lines[0]" - msg: "Oh noes! Switch not running eOS {{eos_version}}!" diff --git a/Section2/playbooks/show_version_with_raw.yaml b/Section2/playbooks/show_version_with_raw.yaml deleted file mode 100644 index c5d1b7c30465174dccfcd81e2e04d186de3db3d4..0000000000000000000000000000000000000000 --- a/Section2/playbooks/show_version_with_raw.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Check the version of code on a switch - hosts: veos - gather_facts: no # or False - tasks: - - name: Gather version from switches - raw: ‘show version’ - register: show_version diff --git a/Section2/playbooks/simple_example_playbook.yaml b/Section2/playbooks/simple_example_playbook.yaml index 8c4f70d53b5468bb949a2b4b452a5dc0c5069900..c4af8631a271e71f7cf087385354e76850299f87 100644 --- a/Section2/playbooks/simple_example_playbook.yaml +++ b/Section2/playbooks/simple_example_playbook.yaml @@ -1,6 +1,11 @@ --- # Oh look, a comment… # …spread out over multiple lines + +# This is not a real playbook - please do not attempt to run it. +# If you do it anyway, you will get this error: +# "ERROR! no module/action detected in task." + - name: Set up Apache # Or nginx, or Mongoose hosts: webservers tasks: @@ -8,4 +13,4 @@ - name: generate Apache config file - name: download Web content to relevant directory - name: restart Apache - - name: eat cake + - name: eat cake \ No newline at end of file diff --git a/Section2/playbooks/tree.txt b/Section2/playbooks/tree_directory_structure.txt similarity index 100% rename from Section2/playbooks/tree.txt rename to Section2/playbooks/tree_directory_structure.txt diff --git a/Section2/playbooks/simple_variables.yaml b/Section2/playbooks/variable_files.yaml similarity index 100% rename from Section2/playbooks/simple_variables.yaml rename to Section2/playbooks/variable_files.yaml