Karl Bielefeldt
Karl Bielefeldt

Reputation: 49008

Specifying a group variable on the ansible command line

Ansible allows the creation of variables that pertain only to a group in the inventory file as follows:

[DC1:vars]
node_availability=available

[DC2:vars]
node_availability=unavailable

I would like to do this on the command line instead, using the --extra-vars parameter. Any idea how this may be accomplished? I've tried various permutations of group.DC1.node_availability=available and the like to no avail.

Upvotes: 1

Views: 2110

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68229

Extra vars are different thing, so you can't set group vars via command line directly.
But you can template group vars, like this:

[DC1:vars]
node_availability={{dc1var | default('unavailable')}}

And passing -e dc1var=test will thus set your group variable.

Upvotes: 1

Related Questions