Possible bug in split_args

44 views
Skip to first unread message

Gabriele Favalessa

unread,
Apr 6, 2015, 8:43:36 AM4/6/15
to ansible...@googlegroups.com
Hi all,

I'm wondering if this is the intended behavior of split_args (ansible 1.9.0.1):

>>> from ansible.module_utils.splitter import split_args                                                                       
>>> split_args('content="  a  b"')                                                                                             
[u'content="  a  b"']
>>> split_args('content="  a\n  b"')                                                                                           
[u'content="  a\nb"']

i.e. if stripping the spaces after the new line is how split_args is supposed to work.

Because spaces are stripped, this is not working for me:

- name: Create YAML from some variable
  copy: content={{ some_variable | to_nice_yaml }} dest=/some/file

since the indentation of the YAML is broken once the spaces are removed.

BTW my original problem was encrypting a YAML configuration file (not an ansible playbook, just a configuration file for my application that I wanted to store encrypted before copying it to the deployment server.) To the best of my understanding it's not possible to put a file in the vault, so I stored the YAML in an encrypted vars file instead. But then I stumbled into the reported bug, preventing me to recreate a valid human readable YAML file from the variable. My current solution is to write {{ some_variable | to_json }} exploiting the fact that JSON is also valid YAML but indentation is not significative at the expense of some readability.

Gabriele

James Cammarata

unread,
Apr 6, 2015, 4:51:31 PM4/6/15
to ansible...@googlegroups.com
Hi Gabrielle, did this happen prior to 1.9.0.1?

James Cammarata
Director, Ansible Core Engineering
github: jimi-c

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0143ef02-b438-43e8-96be-77ea8a4a2c17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gabriele Favalessa

unread,
Apr 6, 2015, 6:15:18 PM4/6/15
to ansible...@googlegroups.com


On Monday, April 6, 2015 at 10:51:31 PM UTC+2, James Cammarata wrote:
Hi Gabrielle, did this happen prior to 1.9.0.1?

I quickly checked 1.8 which behaves like 1.9.0.1 and 1.7 which behaves as I would expect:

>>> import ansible
>>> ansible.__version__
'1.7'
>>> from ansible.module_utils.splitter import split_args 
>>> split_args('content="  a\n  b"')  
[u'content="  a\n  b"']

i.e. the spaces before 'b' are not removed.

Gabriele
Reply all
Reply to author
Forward
0 new messages