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?
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.
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.
Specify both but separately.
--extra-vars "@some_file.json" --extra-vars "key=value"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With