From 0677bd0255f5e9238352e33f4538b2fb36a53e67 Mon Sep 17 00:00:00 2001 From: Vlad Raducanu Date: Thu, 30 Jun 2022 12:53:21 +0100 Subject: [PATCH] Initial test of DNAC module for Ansible - not great... --- dnac/credentials.yml | 19 +++++++++++++++ dnac/get_device_info.yml | 26 ++++++++++++++++++++ dnac/inventory.yml | 4 ++++ dnac/main.yml | 41 +++++++++++++++++++++++++++++++ dnaclab_linux/inventory.yml | 48 ++++++++++++++++++------------------- 5 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 dnac/credentials.yml create mode 100644 dnac/get_device_info.yml create mode 100644 dnac/inventory.yml create mode 100644 dnac/main.yml diff --git a/dnac/credentials.yml b/dnac/credentials.yml new file mode 100644 index 0000000..19007e0 --- /dev/null +++ b/dnac/credentials.yml @@ -0,0 +1,19 @@ +$ANSIBLE_VAULT;1.1;AES256 +32353864313261346632336363373830643332303964323331346636333034663531646636313737 +3161656564643166346138643232326431323335323834340a336634323365376633323938613865 +66663464313534633339303231353636333661363266336131383463613261373563633162303065 +3862326433316265320a393466356266633464313165383330666237323737633865643763383665 +63613932353263626531306431373833333666396361633039633363383864653637353161323230 +33643234323864373434306131376235393363306334303036366232633436643663656139323562 +65316261383939343363363962623434636239376139336366636166313931393461623863633230 +38373232303666323661343934313732323865626464383965316562656436666265363939366265 +64363734663532643636363231373432336435343334633233633236383937363561343334346166 +30663039353034653066663434633036623563663931333063663337343531626633316263383630 +39373163303764366533666538393438643764643936636430366334316232323734353561376436 +31613136363631636662376339393034613831663530373939656236313264373465623930323431 +36303532616466323031623937333234373938333266393862356639363338316563316462633662 +61333436323431613266623235343637666435613661636465666538326437333461633664643137 +66643636313538633165326137383064303331353336636265616265656164623439306562626366 +35613135393564636562373863653762613130613365653837306539386431383831623133623961 +62356664333731386336323831346236343466346665613264636630646130346366653237313363 +3437303231326335646361383131313339643763303130626439 diff --git a/dnac/get_device_info.yml b/dnac/get_device_info.yml new file mode 100644 index 0000000..39e8ad9 --- /dev/null +++ b/dnac/get_device_info.yml @@ -0,0 +1,26 @@ +--- +- name: DNAC test playbook - retrieves hostname, MGMT IP and SN for devices in the inventory and displays them + hosts: all + vars_files: + - credentials.yml + gather_facts: no + + tasks: + + - name: Get network device list + cisco.dnac.network_device_info: + dnac_host: "{{ dnac_host }}" + dnac_username: "{{ dnac_username }}" + dnac_password: "{{ dnac_password }}" + dnac_verify: "{{ dnac_verify }}" + dnac_port: "{{ dnac_port }}" + dnac_version: "{{ dnac_version }}" + dnac_debug: "{{ dnac_debug }}" + register: result + + - name: Print device info + ansible.builtin.debug: + msg: "Device {{ item['hostname'] }} is reachable on {{ item['managementIpAddress'] }} and has SN {{ item['serialNumber'] }}" + loop: "{{ result['dnac_response']['response'] }}" + loop_control: + label: result \ No newline at end of file diff --git a/dnac/inventory.yml b/dnac/inventory.yml new file mode 100644 index 0000000..7532f36 --- /dev/null +++ b/dnac/inventory.yml @@ -0,0 +1,4 @@ +--- +all: + hosts: + dnac.dnaclab.net: \ No newline at end of file diff --git a/dnac/main.yml b/dnac/main.yml new file mode 100644 index 0000000..24d53e9 --- /dev/null +++ b/dnac/main.yml @@ -0,0 +1,41 @@ +--- +- name: DNAC test playbook - retrieves hostname, MGMT IP and SN for devices in the inventory and displays them + hosts: all + vars_files: + - credentials.yml + gather_facts: no + + tasks: + + - name: Get all Site + cisco.dnac.site_info: + dnac_host: "{{dnac_host}}" + dnac_username: "{{dnac_username}}" + dnac_password: "{{dnac_password}}" + dnac_verify: "{{dnac_verify}}" + dnac_port: "{{dnac_port}}" + dnac_version: "{{dnac_version}}" + dnac_debug: "{{dnac_debug}}" + register: sda_sites + + - name: Print 1 + ansible.builtin.debug: + msg: "{{ sda_sites['dnac_response']['response'][1]['siteNameHierarchy'] }}" + + + - name: Get network device list + cisco.dnac.sda_virtual_network_info: + dnac_host: "{{ dnac_host }}" + dnac_username: "{{ dnac_username }}" + dnac_password: "{{ dnac_password }}" + dnac_verify: "{{ dnac_verify }}" + dnac_port: "{{ dnac_port }}" + dnac_version: "{{ dnac_version }}" + dnac_debug: "{{ dnac_debug }}" + virtualNetworkName: CORP_VN + # siteNameHierarchy: "{{ sda_sites['dnac_response']['response'][1]['siteNameHierarchy'] }}" + register: result + + - name: Print 2 + ansible.builtin.debug: + msg: "{{ result }}" diff --git a/dnaclab_linux/inventory.yml b/dnaclab_linux/inventory.yml index c501e6b..d406d67 100644 --- a/dnaclab_linux/inventory.yml +++ b/dnaclab_linux/inventory.yml @@ -1,25 +1,25 @@ --- - all: - children: - services: - hosts: - ubuntu.dnaclab.net: - telemetry: - hosts: - telemetry.dnaclab.net: - developer: - hosts: - developer.dnaclab.net: - gitlab: - hosts: - gitlab.dnaclab.net: - test: - hosts: - test.dnaclab.net: - all_servers: - hosts: - ubuntu.dnaclab.net: - telemetry.dnaclab.net: - developer.dnaclab.net: - gitlab.dnaclab.net: - test.dnaclab.net: +all: + children: + services: + hosts: + ubuntu.dnaclab.net: + telemetry: + hosts: + telemetry.dnaclab.net: + developer: + hosts: + developer.dnaclab.net: + gitlab: + hosts: + gitlab.dnaclab.net: + test: + hosts: + test.dnaclab.net: + all_servers: + hosts: + ubuntu.dnaclab.net: + telemetry.dnaclab.net: + developer.dnaclab.net: + gitlab.dnaclab.net: + test.dnaclab.net: