Exercise 1.1: Using the bigip_device_info module¶
Objective¶
Demonstrate use of the BIG-IP Info module to grab facts (useful information) from a F5 BIG-IP device and display them to the terminal window using the debug module.
Guide¶
Step 1:¶
Using VSCode create a new file called bigip-info.yml by clicking the new file icone in the left pane.
Step 2:¶
Ansible playbooks are YAML files. YAML is a structured encoding format that is also extremely human readable (unlike it’s subset - the JSON format).
Enter the following play definition into bigip-info.yml:
--- - name: GRAB F5 FACTS hosts: f5 connection: local gather_facts: falseInformation:
The
---
at the top of the file indicates that this is a YAML file.The
hosts: f5
, indicates the play is run only on the F5 BIG-IP device
connection: local
tells the Playbook to run locally (rather than SSHing to itself)
gather_facts: no
disables facts gathering.
Step 3:¶
Next, add the first
task
. This task will use thebigip_device_info
module to grab useful information from the BIG-IP device.tasks: - name: COLLECT BIG-IP FACTS f5networks.f5_modules.bigip_device_info: gather_subset: - system-info provider: server: "{{ ansible_host }}" user: "{{ ansible_user }}" password: "{{ ansible_password }}" server_port: "{{ server_port }}" no_f5_teem: yes validate_certs: false register: device_factsA play is a list of tasks. Tasks and modules have a 1:1 correlation. Ansible modules are reusable, standalone scripts that can be used by the Ansible API, or by the ansible or ansible-playbook programs. They return information to ansible by printing a JSON string to stdout before exiting.
The
name: COLLECT BIG-IP FACTS
is a user defined description that will display in the terminal output.The
bigip_device_info:
tells the task which module to use. Everything exceptregister
is a module parameter defined on the module documentation page.The
gather_subset: system_info
parameter tells the module only to grab system level information.The
provider:
parameter is a group of connection details for the BIG-IP.
The
server: "{{ ansible_host }}"
parameter tells the module to connect to the F5 BIG-IP IP address, which is stored as a variableansible_host
in inventoryThe
user: "{{ ansible_user }}"
parameter tells the module the username to login to the F5 BIG-IP device withThe
password: "{{ ansible_password }}"
parameter tells the module the password to login to the F5 BIG-IP device withThe
server_port: "{{ server_port }}
parameter tells the module the port to connect to the F5 BIG-IP device withThe
no_f5_teem: yes
parameter tells the module if TEEM telemetry data is or is not sent to F5 BIG-IP Device.The
validate_certs: false
parameter tells the module to not validate SSL certificates. This is just used for demonstration purposes since this is a lab.The
register: device_facts
tells the task to save the output to a variable bigip_device_info
Step 4:¶
Next, append the second
task
to above . This task will use thedebug
module to print the output from device_facts variable we registered the facts to. Make sure that the- name
is aligned with the previous task or the code will fail to execute. In YAML alignment of code is necessary!!- name: DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION debug: var: device_factsInformation:
The
name: COMPLETE BIG-IP SYSTEM INFORMATION
is a user defined description that will display in the terminal output.
debug:
tells the task to use the debug module.The
var: device_facts
parameter tells the module to display the variable bigip_device_info.Save the file and exit out of editor.
Step 5:¶
Change directory to the
Users Directory
folder to execute the codecd ~Run the playbook - Open Terminal in the VS Code server of the control host and execute the following:
ansible-navigator run bigip-info.yml --mode stdoutThe output will look as follows.
[rhel-user@ede7a345-c0f1-47f9-a73b-74fded8ec113 ~]$ ansible-navigator run bigip_info.yml --mode stdout PLAY [GRAB F5 FACTS] *********************************************************** TASK [COLLECT BIG-IP FACTS] **************************************************** ok: [f5] TASK [DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION] ****************************** ok: [f5] => { "device_facts": { "ansible_facts": { "ansible_net_queried": true, "ansible_net_system_info": { "base_mac_address": "52:54:00:46:88:7d", "chassis_serial": "1e5a6bf2-42ff-e242-0b0590f7b1ba", "hardware_information": [ { "model": "Intel(R) Xeon(R) CPU @ 2.20GHz", "name": "cpus", "type": "base-board", "versions": [ { "name": "cache size", "version": "16384 KB" }, { "name": "cores", "version": "8 (physical:8)" }, { "name": "cpu MHz", "version": "2199.998" }, { "name": "cpu sockets", "version": "1" }, { "name": "cpu stepping", "version": "0" } ] } ], "marketing_name": "BIG-IP Virtual Edition", "package_edition": "Final", "package_version": "Build 0.0.6 - Fri Oct 20 05:44:41 PDT 2023", "platform": "Z100", "product_build": "0.0.6", "product_build_date": "Fri Oct 20 05:44:41 PDT 2023", "product_built": 231020054441, "product_changelist": 3725004, "product_code": "BIG-IP", "product_jobid": 1446006, "product_version": "17.1.1", "time": { "day": 8, "hour": 20, "minute": 29, "month": 1, "second": 49, "year": 2024 }, "uptime": 9674 } }, "changed": false, "failed": false, "queried": true, "system_info": { "base_mac_address": "52:54:00:46:88:7d", "chassis_serial": "1e5a6bf2-42ff-e242-0b0590f7b1ba", "hardware_information": [ { "model": "Intel(R) Xeon(R) CPU @ 2.20GHz", "name": "cpus", "type": "base-board", "versions": [ { "name": "cache size", "version": "16384 KB" }, { "name": "cores", "version": "8 (physical:8)" }, { "name": "cpu MHz", "version": "2199.998" }, { "name": "cpu sockets", "version": "1" }, { "name": "cpu stepping", "version": "0" } ] } ], "marketing_name": "BIG-IP Virtual Edition", "package_edition": "Final", "package_version": "Build 0.0.6 - Fri Oct 20 05:44:41 PDT 2023", "platform": "Z100", "product_build": "0.0.6", "product_build_date": "Fri Oct 20 05:44:41 PDT 2023", "product_built": 231020054441, "product_changelist": 3725004, "product_code": "BIG-IP", "product_jobid": 1446006, "product_version": "17.1.1", "time": { "day": 8, "hour": 20, "minute": 29, "month": 1, "second": 49, "year": 2024 }, "uptime": 9674 } } } PLAY RECAP ********************************************************************* f5 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Step 6:¶
Finally let’s append two more tasks to get more specific info from facts gathered, to the above playbook.
- name: DISPLAY ONLY THE MAC ADDRESS debug: var: device_facts['system_info']['base_mac_address'] - name: DISPLAY ONLY THE VERSION debug: var: device_facts['system_info']['product_version']Information:
var: device_facts['system_info']['base_mac_address']
displays the MAC address for the Management IP on the BIG-IP device
device_facts['system_info']['product_version']
displays the product version BIG-IP deviceBecause the bigip_device_info module returns useful information in structured data, it is really easy to grab specific information without using regex or filters. Fact modules are very powerful tools to grab specific device information that can be used in subsequent tasks, or even used to create dynamic documentation (reports, csv files, markdown).
Step 7:¶
Run the playbook - Save the file and execute the code within the Terminal window:
ansible-navigator run bigip-info.yml --mode stdoutPlaybook Output
The output will look as follows.
[rhel-user@ede7a345-c0f1-47f9-a73b-74fded8ec113 ~]$ ansible-navigator run bigip_info.yml --mode stdout PLAY [GRAB F5 FACTS] *********************************************************** TASK [COLLECT BIG-IP FACTS] **************************************************** ok: [f5] TASK [DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION] ****************************** ok: [f5] => { "device_facts": { "ansible_facts": { "ansible_net_queried": true, "ansible_net_system_info": { "base_mac_address": "52:54:00:46:88:7d", "chassis_serial": "1e5a6bf2-42ff-e242-0b0590f7b1ba", "hardware_information": [ { "model": "Intel(R) Xeon(R) CPU @ 2.20GHz", "name": "cpus", "type": "base-board", "versions": [ { "name": "cache size", "version": "16384 KB" }, { "name": "cores", "version": "8 (physical:8)" }, { "name": "cpu MHz", "version": "2199.998" }, { "name": "cpu sockets", "version": "1" }, { "name": "cpu stepping", "version": "0" } ] } ], "marketing_name": "BIG-IP Virtual Edition", "package_edition": "Final", "package_version": "Build 0.0.6 - Fri Oct 20 05:44:41 PDT 2023", "platform": "Z100", "product_build": "0.0.6", "product_build_date": "Fri Oct 20 05:44:41 PDT 2023", "product_built": 231020054441, "product_changelist": 3725004, "product_code": "BIG-IP", "product_jobid": 1446006, "product_version": "17.1.1", "time": { "day": 8, "hour": 20, "minute": 32, "month": 1, "second": 45, "year": 2024 }, "uptime": 9850 } }, "changed": false, "failed": false, "queried": true, "system_info": { "base_mac_address": "52:54:00:46:88:7d", "chassis_serial": "1e5a6bf2-42ff-e242-0b0590f7b1ba", "hardware_information": [ { "model": "Intel(R) Xeon(R) CPU @ 2.20GHz", "name": "cpus", "type": "base-board", "versions": [ { "name": "cache size", "version": "16384 KB" }, { "name": "cores", "version": "8 (physical:8)" }, { "name": "cpu MHz", "version": "2199.998" }, { "name": "cpu sockets", "version": "1" }, { "name": "cpu stepping", "version": "0" } ] } ], "marketing_name": "BIG-IP Virtual Edition", "package_edition": "Final", "package_version": "Build 0.0.6 - Fri Oct 20 05:44:41 PDT 2023", "platform": "Z100", "product_build": "0.0.6", "product_build_date": "Fri Oct 20 05:44:41 PDT 2023", "product_built": 231020054441, "product_changelist": 3725004, "product_code": "BIG-IP", "product_jobid": 1446006, "product_version": "17.1.1", "time": { "day": 8, "hour": 20, "minute": 32, "month": 1, "second": 45, "year": 2024 }, "uptime": 9850 } } } TASK [DISPLAY ONLY THE MAC ADDRESS] ******************************************** ok: [f5] => { "device_facts['system_info']['base_mac_address']": "52:54:00:46:88:7d" } TASK [DISPLAY ONLY THE VERSION] ************************************************ ok: [f5] => { "device_facts['system_info']['product_version']": "17.1.1" } PLAY RECAP ********************************************************************* f5 : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Solution¶
The finished Ansible Playbook is provided here for an Answer key. Click here for bigip-info.yml.
Going Further¶
For this bonus exercise add the
tags: debug
parameter (at the task level) to the existing debug task.- name: DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION debug: var: device_facts tags: debugNow re-run the playbook with the
--skip-tags-debug
command line option.ansible-navigator run bigip-info.yml --skip-tags=debug --mode stdout
The Ansible Navigator will only run three tasks, skipping the
DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION
task.
You have finished this exercise.