Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible, spaces in command line variables

Tags:

ansible

I am about to bump up the changelog of a lot of locally developed debian packages. I am using 'Ansible' to call 'dch' from the devscripts package. I am using Ansible because I already have the subversion paths to the packages listed in an Ansible variable. I would like to be able to enter the actual changelog message as a command line variable, but it seems that ansible cannot parse spaces in variables entered on the command line.

I have tried

ansible-playbook tag_changelog_on_packages.yml -e changelog_message="testing testing"
ansible-playbook tag_changelog_on_packages.yml -e changelog_message='testing testing'
ansible-playbook tag_changelog_on_packages.yml -e changelog_message=testing\ testing
ansible-playbook tag_changelog_on_packages.yml -e changelog_message="testing\ testing"

In all cases I only get the first "testing" . The last try makes ansible crash with ValueError: No escaped character probably because the whitespace is stripped.

Am I missing anything ?

Cheers

like image 252
Kristian Rune Larsen Avatar asked Sep 15 '15 10:09

Kristian Rune Larsen


1 Answers

That is because it is processed by shell first which eats the quotes and backslashes you used.

You can enclose the whole argument into single quotes which tells shell not to touch what is inside. Then the value of the variable can be enclosed into double quotes, which will remain there for ansible.

ansible-playbook tag_changelog_on_packages.yml -e 'changelog_message="testing testing"'

EDIT: As Ken Pronovici pointed out in the comment, reversing the quotation marks makes more sense as it enables the use of shell vars:

-e "name='${NAME}'"

like image 186
mitroo Avatar answered Sep 22 '22 13:09

mitroo