Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a file and variables through --extra-vars

I see that files can supply variables to Ansible through the command line using --extra-vars "@some_file.json", or variables can be set in strings as key=value. Is it possible to do both? And if so, what's the syntax?

like image 645
snl Avatar asked Jan 23 '16 04:01

snl


People also ask

How do you pass extra vars in ansible?

To pass a value to nodes, use the --extra-vars or -e option while running the Ansible playbook, as seen below. This ensures you avoid accidental running of the playbook against hardcoded hosts.

What is extra vars in ansible?

Ansible extra vars is a feature that allows you to include more flexibility in your Ansible playbooks by providing you with the ability to specify dynamic values when executing the playbook. Ansible extra vars are helpful when: You have a variable whose value may change more than once when running the playbook.


2 Answers

Specify both but separately.

--extra-vars "@some_file.json" --extra-vars "key=value" 
like image 131
helloV Avatar answered Sep 19 '22 13:09

helloV


If you are using it with vagrant then here is the answer:

  config.vm.provision :ansible do |ansible| 
    ansible.playbook = "playbook.yml"
    ansible.extra_vars = { ansible_ssh_user: 'vagrant' }
  end

hope this will help you.

like image 44
Arbab Nazar Avatar answered Sep 21 '22 13:09

Arbab Nazar