Skip to content

Instantly share code, notes, and snippets.

@blanchg
Created August 27, 2018 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blanchg/4afa62e0fccb3d55111b0f7376ba0416 to your computer and use it in GitHub Desktop.
Save blanchg/4afa62e0fccb3d55111b0f7376ba0416 to your computer and use it in GitHub Desktop.
Demonstrate use of repeat_for in ansible command parser json_templates
- name: setup dummy data
set_vars:
data:
- bob
- jane
- roger
- name: template test
json_template:- name: setup dummy data
set_vars:
data:
- name: Bob
type: user
- name: Jane
type: admin
- name: Roger
type: user
- name: template test
export: true
export_as: list
register: test_facts
json_template:
template:
- key: names
elements: "{{ item.name }}"
repeat_for: "{{ data }}"
- key: count
value: "{{ data | length }}"
key: names
elements: "{{ item }}"
repeat_for: "{{ data }}"
- hosts: localhost
vars:
ansible_network_os: ios
facts: "{{ ansible_facts['test_facts'] }}"
roles:
- "ansible-network.network-engine"
tasks:
- name: parse commands
command_parser:
file: "json_template_repeat.yaml"
content: ""
register: result
- debug:
msg: "{{ facts }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment