Thanks, Richard, but I was looking for a specific solution which seems to
be tricky.
On Tuesday, December 27, 2022 at 10:18:27 PM UTC+5:30 Richard Megginson
wrote:
> `split` is not an ansible filter - you cannot use it like `|
> split(something)` - you have to use as a string method which is why
> `instance_name.split(',')` works
>
> On Tue, Dec 27, 2022 at 7:04 AM Know-Your-Tech <[email protected]> wrote:
>
>> Below is how i call my ansible-playbook and pass application names as
>> parameters APP1 & APP2
>>
>> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts
>> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e
>> instance_name=APP1,APP2
>>
>> Playbook:
>>
>> ---
>> - hosts: "{{ [ENV] | product(instance_name.split(',')) | product([NODE])
>> | product(['wladmin_mmsplit'])|map('flatten')|map('join', '_') }}"
>> user: wladmin
>> gather_facts: no
>>
>> I get the desired Output as below:
>>
>> PLAY [['qa_APP1_cluster_wladmin_mmsplit',
>> 'qa_APP2_cluster_wladmin_mmsplit']]
>>
>> The problem occurs when i pass the application names as
>> APP1-brazil & APP2-Chile
>>
>> and wish the same output as before.
>>
>> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts
>> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e
>> instance_name=APP1-brazil,APP2-Chile
>>
>> I tried the below but i get error:
>>
>> - hosts: "{{ [ENV] | product(instance_name.split(',') | split('-')[0]) |
>> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join',
>> '_') }}"
>>
>> Error in output:
>>
>> ERROR! template error while templating string: expected token ',', got
>> '['. String: {{ [ENV] | product(instance_name.split(',') | split('-')[0]) |
>> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join',
>> '_') }}
>>
>> Can you please suggest how can i address this requirement?
>>
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/da1f5460-e7c8-4e84-814a-ed3b2e3a9828n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/da1f5460-e7c8-4e84-814a-ed3b2e3a9828n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5ab85cf8-d627-4092-afc6-a7bd7d883a0dn%40googlegroups.com.