chafik bel
chafik bel

Reputation: 161

Ansible nested variables in command line

I have some variables in my playbook as follows:

--- first_var: param1: value1 param2: value2

And I want to call these parametres from the commandline as follows:

ansible-playbook -i inventory site.yml -e 'first_var.param1=newvalue1'

But doesn't work, am I missing something?

Upvotes: 5

Views: 1675

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

You can do this only if you modify hash-behaviour to merge (this can potentialy brake your playbooks).
Also for this to work, you need to pass extra variables as JSON object, this will not work for -e var=value.

Example command line:

ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook -i inventory -e "{'first_var':{'param1':'newvalue1'}}" site.yml

Upvotes: 4

Related Questions