Last active
October 18, 2016 17:15
-
-
Save brackendawson/84cc0f771f64faa1a32a11bfb80be84b to your computer and use it in GitHub Desktop.
The list problem
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: all | |
gather_facts: False | |
tasks: | |
- set_fact: | |
myhosts: | |
- 127.0.0.1 | |
- 127.0.0.2 | |
- 127.0.0.3 | |
# I want to put this list in a file, formatted as so: ["127.0.0.1", "127.0.0.2", "127.0.0.3"] | |
# But ansible sees it as a list and the output becomes the pythonic: ['127.0.0.1', '127.0.0.2', '127.0.0.3'] | |
# This comes out as a list, I need a string | |
- set_fact: | |
var: "[ \"{{ myhosts | join('\", \"')}}\" ]" | |
- debug: var=var | |
# This comes out as a string, I need no underscore on it | |
- set_fact: | |
var: "_[ \"{{ myhosts | join('\", \"')}}\" ]" | |
- debug: var=var | |
# This also comes out as a list | |
- set_fact: | |
var: > | |
[ "{{ myhosts | join('", "')}}" ] | |
- debug: var=var | |
# Also parsed as a list | |
- set_fact: | |
var: "{{ myhosts | to_json }}" | |
- debug: var=var | |
# ansible-playbook -i "localhost," list.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment