-
-
Save blanchg/4afa62e0fccb3d55111b0f7376ba0416 to your computer and use it in GitHub Desktop.
Demonstrate use of repeat_for in ansible command parser json_templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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