You can put all your variables in a YAML file and pass it as 
--extra-vars="@my_vars.yml"

Given your example, your command will look like this:
ansible-playbook -i $inventory-file $role-name --extra-vars="@my_vars.yml"

and my_vars.yml should contain:

---
# NOTE: "=" is replaced by ':'

var1: $var1-value
var2: $var2-value


I hope this helps.

On Saturday, September 20, 2014 4:40:46 AM UTC-4, Naween Ghimire wrote:
>
> Hi All,
>
> I am trying to run an ansible playbook from jenkins build to have jenkins 
> trigger my ansible execution.
>
> As part of my ansible-playbook run i need to pass extra-vars to the 
> playbook during execution.
>
> eg:
>
> ansible-playbook -i $inventory-file $role-name 
> --extra-vars"var1=$var1-value, var2=$var2-value"
>
> when i put this line in the execute shell of jenkins the double quotes are 
> evaluated and so aren't available to the ansible-playbook command, so i 
> escaped them as follows:
>
> ansible-playbook -i $inventory-file $role-name 
> --extra-vars\"var1=$var1-value, var2=$var2-value\"
>
> But if i do this, 
>
> shell adds extra quotes around it as below:
>
> ansible-playbook -i <inventory-file-name> <role-name> --extra-vars ' 
> "var1=var1-value,' var2=var2-value, 'var3=var3-value " '
>
> And ansible give the following error:
>
>
> Traceback (most recent call last):
>
>   File "/usr/local/bin/ansible-playbook", line 317, in <module>
>
>     sys.exit(main(sys.argv[1:]))
>
>   File "/usr/local/bin/ansible-playbook", line 148, in main
>
>     extra_vars = utils.combine_vars(extra_vars, 
> utils.parse_kv(extra_vars_opt))
>
>   File "/Library/Python/2.7/site-packages/ansible/utils/__init__.py", line 
> 621, in parse_kv
>
>     vargs = split_args(args)
>
>   File "/Library/Python/2.7/site-packages/ansible/utils/splitter.py", line 
> 148, in split_args
>
>     raise Exception("error while splitting arguments, either an unbalanced 
> jinja2 block or quotes")
>
> Exception: error while splitting arguments, either an unbalanced jinja2 
> block or quotes
>
>
> Has anyone come across such a situation before ?
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/709a4477-de4c-42ad-887c-f075f0f5a503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to