Skip to content

Instantly share code, notes, and snippets.

@brackendawson
Last active October 18, 2016 17:15
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 brackendawson/84cc0f771f64faa1a32a11bfb80be84b to your computer and use it in GitHub Desktop.
Save brackendawson/84cc0f771f64faa1a32a11bfb80be84b to your computer and use it in GitHub Desktop.
The list problem
---
- 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