Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (33 sloc) 1.17 KB
- hosts: localhost
connection: local
# A loop with a static list of items. We simply declare a list to loop over
# in YAML format
- name: Loop with a static list of items
msg: "{{ item}}"
- A
- B
# Here, we loop over the result of a Jinja2 expression. Note that
# ansible_facts.env is a dictionary, but we can only loop over
# lists, so we use items() first to convert the dictionary into a list
# To make this work with Python3, we also apply the list filter
# Each item in the list will be a pair of key and value
# We also use loop_control / label to limit the output to the variable
# name
- name: Loop over all environment variables
msg: "{{ item.0 }}"
"{{ ansible_facts.env.items() | list }}"
"{{ item.0 }}"
register: loopOutput
# As we have registered loopOutput with the loop, it will
# contain the output for all iterations in an item called results
- name: Print loopOutput
var: loopOutput.results
You can’t perform that action at this time.