How to access a specific list item from a join in Ansible

Viewed 40

I have the current working setup and using Ansible 2.3:

environment_vars_docmosis_hosts: "{{ groups['role_ccm_docmosis'] | intersect(groups ['stack_' ~ stack]) }}"

Which resolves to two hostnames: hostname1 and hostname2

I am trying to extract the only hostname1 from the above.

When I try using environment_vars_docmosis_hosts.0 or environment_vars_docmosis_hosts[0] from this expression:

_docmosis_pool_config: "{{ (environment_vars_docmosis_hosts[0] | default(['localhost'])) | join(':2100,') }}:2100"

I only get the first character of the hostname

What would be a proper way of accessing the first hostname ?

2 Answers

to debug:

- name: debug zzzzzzzzzzzzzzz
  debug:
    msg: "{{ (environment_vars_docmosis_hosts[0] | d('localhost')) ~ ':2100' }}"

The join above was wrong.

This works: environment_vars_docmosis_hosts[0] | default(['localhost'])}}:2100"

Related