Skip to content

Instantly share code, notes, and snippets.

@msaladna
Created November 22, 2019 17:11
Show Gist options
  • Save msaladna/bd8a5f493d4687441b8a061e61dc4023 to your computer and use it in GitHub Desktop.
Save msaladna/bd8a5f493d4687441b8a061e61dc4023 to your computer and use it in GitHub Desktop.
- hosts: localhost
gather_facts: no
vars:
subexpr: myvar
powerdns_driver: mysql
powerdns_config_file: /etc/pdns/pdns.conf
dict:
"a{{ subexpr }}-def": "C visible"
"myvar-b": "{{ subexpr_undef | default('foo') }}"
"myvar-c": >-
"{{ subexpr }}"
tasks:
- set_fact:
var2: "{{ dict | combine({}) }}"
- debug: msg="{{ item.key }} - {{ item.value }}"
loop: "{{ var2 | dict2items }}"
@sivel
Copy link

sivel commented Nov 22, 2019

my output:

ok: [localhost] => (item={'key': u'myvar-c', 'value': u'"myvar"'}) => {
    "msg": "myvar-c - \"myvar\""
}
ok: [localhost] => (item={'key': u'myvar-b', 'value': u'foo'}) => {
    "msg": "myvar-b - foo"
}
ok: [localhost] => (item={'key': u'amyvar-def', 'value': u'C visible'}) => {
    "msg": "amyvar-def - C visible"
}

@msaladna
Copy link
Author

My broken variation:

ok: [localhost] => (item={'key': u'myvar-c', 'value': u'"myvar"'}) =>
msg: myvar-c - "myvar"
ok: [localhost] => (item={'key': u'myvar-b', 'value': u'foo'}) =>
msg: myvar-b - foo
ok: [localhost] => (item={'key': u'a{{ subexpr }}-def', 'value': u'C visible'}) =>
msg: a{{ subexpr }}-def - C visible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment