Lists can be provided to a module through vars specified inside a Playbook or they can be provided directly inside a Task.

In the examples below we want to send two “show” commands to the devices. The former example uses a vars  list while the latter defines the list inside of the module call:

List inside vars:

- name: run show commands
  hosts: all
  connection: local
  gather_facts: no

  vars:
    command_list:
      - show interface summary
      - show ip interface brief

  tasks:
    - name: run show commands
      ios_command:
        provider: ""
        commands: "{{ command_list }}"
      register: show_output

List inside Task:

- name: show commands
  ios_command:
    provider: ""
    commands:
      - show interface summary
      - show ip interface brief
  register: show_output

Both methods work perfectly fine, though the former is more flexible as it can be reused across multiple Tasks.


As always, if you have any questions or have a topic that you would like me to discuss, please feel free to post a comment at the bottom of this blog entry, e-mail at will@oznetnerd.com, or drop me a message on Reddit (OzNetNerd).

Note: The opinions expressed in this blog are my own and not those of my employer.

Leave a comment