Exercise 1.1: Using the bigip_device_info module

Objective

Demonstrate use of the BIG-IP Facts module to grab facts (useful information) from a F5 BIG-IP device and display them to the terminal window using the debug module.

Guide

Make sure you are in the home directory

[centos@ansible networking-workshop]$ cd ~

Step 1:

Use VS Code Explorer to create a new file called bigip-facts.yml.

The Ansible node is equiped with Visual Studio Code and can be accessed via UDF ACCESS Methods.

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-facts.yml:

---
- name: GRAB F5 FACTS
  hosts: f5
  connection: local
  gather_facts: no
  • 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. We are not using any fact variables for this playbook.

Do not close editor yet.

Step 3

Next, add the first task. This task will use the bigip_device_info module to grab useful information from the BIG-IP device.

Warning

The tasks: item should line up to the same indentation as gather_facts: while the - name: item should be indented 2 spaces under tasks:

tasks:

  - name: COLLECT BIG-IP FACTS
    bigip_device_info:
      gather_subset:
       - system-info
      provider:
        server: "{{private_ip}}"
        user: "{{ansible_user}}"
        password: "{{ansible_ssh_pass}}"
        server_port: 8443
        validate_certs: no
    register: device_facts
A 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.
  • name: COLLECT BIG-IP FACTS is a user defined description that will display in the terminal output.
  • bigip_device_info: tells the task which module to use. Everything except register 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: "{{private_ip}}" parameter tells the module to connect to the F5 BIG-IP IP address, which is stored as a variable private_ip in inventory
  • The user: "{{ansible_user}}" parameter tells the module the username to login to the F5 BIG-IP device with
  • Thepassword: "{{ansible_ssh_pass}}" parameter tells the module the password to login to the F5 BIG-IP device with
  • The server_port: 8443 parameter tells the module the port to connect to the F5 BIG-IP device with. 8443 is what’s being used in this lab, but could be different depending on the deployment.
  • 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 the debug module to print the output from device_facts variable we registered the facts to.

- name: DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION
  debug:
    var: device_facts
  • 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

Run the playbook - exit back into the command line of the control host and execute the following:

[centos@ansible ~]$ ansible-playbook bigip-facts.yml

The output will look as follows.

[centos@ansible ~]$ ansible-playbook bigip-facts.yml

PLAY [GRAB F5 FACTS] *****************************************************************************************************************************************

TASK [COLLECT BIG-IP FACTS] **********************************************************************************************************************************
ok: [f5]

TASK [DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION] ************************************************************************************************************
ok: [f5] =>
  device_facts:
    ansible_facts:
      discovered_interpreter_python: /usr/bin/python
    changed: false
    failed: false
    queried: true
    system_info:
      base_mac_address: 06:95:66:ab:b6:1c
      chassis_serial: a2ad2fec-c283-2cc9-3610e7425914
      hardware_information:
      - model: Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
        name: cpus
        type: base-board
        versions:
        - name: cpu stepping
          version: '2'
        - name: cpu sockets
          version: '1'
        - name: cpu MHz
          version: '2900.042'
        - name: cores
          version: 8  (physical:4)
        - name: cache size
          version: 25600 KB
      marketing_name: BIG-IP Virtual Edition
      package_edition: Final
      package_version: Build 0.0.11 - Fri Aug  2 21:38:03 PDT 2019
      platform: Z100
      product_build: 0.0.11
      product_build_date: Fri Aug  2 21:38:03 PDT 2019
      product_built: 190802213803
      product_changelist: 3115640
      product_code: BIG-IP
      product_jobid: 1128587
      product_version: 15.0.1
      time:
        day: 19
        hour: 15
        minute: 41
        month: 2
        second: 1
        year: 2020
      uptime: 9380.0

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']
  • 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 device
Because 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 - exit back into the command line of the control host and execute the following:

[centos@ansible ~]$ ansible-playbook bigip-facts.yml

Playbook Output

The output will look as follows.

[centos@ansible ~]$ ansible-playbook bigip-facts.yml

PLAY [GRAB F5 FACTS] *****************************************************************************************************************************************

TASK [COLLECT BIG-IP FACTS] **********************************************************************************************************************************
ok: [f5]

TASK [DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION] ************************************************************************************************************
ok: [f5] =>
  device_facts:
    ansible_facts:
      discovered_interpreter_python: /usr/bin/python
    changed: false
    failed: false
    queried: true
    system_info:
      base_mac_address: 06:95:66:ab:b6:1c
      chassis_serial: a2ad2fec-c283-2cc9-3610e7425914
      hardware_information:
      - model: Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
        name: cpus
        type: base-board
        versions:
        - name: cpu stepping
          version: '2'
        - name: cpu sockets
          version: '1'
        - name: cpu MHz
          version: '2900.042'
        - name: cores
          version: 8  (physical:4)
        - name: cache size
          version: 25600 KB
      marketing_name: BIG-IP Virtual Edition
      package_edition: Final
      package_version: Build 0.0.11 - Fri Aug  2 21:38:03 PDT 2019
      platform: Z100
      product_build: 0.0.11
      product_build_date: Fri Aug  2 21:38:03 PDT 2019
      product_built: 190802213803
      product_changelist: 3115640
      product_code: BIG-IP
      product_jobid: 1128587
      product_version: 15.0.1
      time:
        day: 19
        hour: 15
        minute: 42
        month: 2
        second: 4
        year: 2020
      uptime: 9443.0

TASK [DISPLAY ONLY THE MAC ADDRESS] **************************************************************************************************************************
ok: [f5] =>
  device_facts['system_info']['base_mac_address']: 06:95:66:ab:b6:1c

TASK [DISPLAY ONLY THE VERSION] ******************************************************************************************************************************
ok: [f5] =>
  device_facts['system_info']['product_version']: 15.0.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-facts.yml.

Going Further

For this bonus exercise add the tags: debug paramteter (at the task level) to the existing debug task.

- name: DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION
  debug:
    var: device_facts
  tags: debug

Now re-run the playbook with the --skip-tags-debug command line option.

ansible-playbook bigip-facts.yml --skip-tags=debug

The Ansible Playbook will only run three tasks, skipping the DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION task.

You have finished this exercise. Click here to return to the lab guide