On Tue, 26 Jan 2021 15:34:09 -0800 (PST) Philip Svensson <[email protected]> wrote:
> how I should point to variables nested like shown below.
>
> vm_specs:
> "{{ hostname }}":
> dns1: 1.1.1.1
> dns2: 2.2.2.2
For example,
shell> cat playbook.yml
- hosts: localhost
vars:
vm_specs:
"{{ hostname }}":
dns1: 1.1.1.1
dns2: 2.2.2.2
tasks:
- set_fact:
my_hostname: "{{ vm_specs.keys()|first }}"
my_dns: "{{ vm_specs.values()|first }}"
- debug:
var: my_hostname
- debug:
var: my_dns
gives
shell> ansible-playbook playbook.yml -e hostname=test
TASK [debug]
*****************************************************
ok: [localhost] =>
my_hostname: test
TASK [debug]
*****************************************************
ok: [localhost] =>
my_dns:
dns1: 1.1.1.1
dns2: 2.2.2.2
--
Vladimir Botka
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20210127044345.176ef3ee%40gmail.com.
pgpeuDCa18bTV.pgp
Description: OpenPGP digital signature
