Argument passing

21 views
Skip to first unread message

zorg...@gmail.com

unread,
Aug 3, 2015, 4:18:46 AM8/3/15
to Ansible Project
Hello,

I've written a role including two python modules, one to provide Ansible with a list of new host names in order to create a dynamic group and another one using the list of all hosts. Here is a part of the main.yml file of the role:

- name: Get list of new hosts
  get_new_hosts
:
 
register: get_new_hosts_return

- name: Create 'new' dynamic group
  add_host
: name={{ item }} group=new
  with_items
: get_new_hosts_return.host_list

- name: DEBUG... check full host list
  debug
: msg={{ groups['all'] }}

- name: Run task using all hosts
  use_all_hosts
: "{host_list: {{ groups['all'] }}, arg2: 'val_2', arg_3: True}"


In the debug task, host names are correctly displayed. Then I run the next python module using the inventory groups['all']. You see that I send arguments as a YAML string and I just read them in the python module through the yaml.load() function. It works correctly but the problem is that I get arguments from the args file as:

{host_list: ['host_name_1', 'host_name_2', ... , u'new_host_name_1', u'new_host_name_2', ...], arg_2: 'val_2', arg_3: True}


Host names from the dynamic group are written as the string u'new_host_name' that is not a Unicode string, just a Python representation of Unicode. Then I cannot read correct names except if I remove the u'' characters.

Is there something wrong in what I wrote? In such a case what?

Thank you in advance for your help.
Reply all
Reply to author
Forward
0 new messages