CHange in playbook made:
- name: Create an empty list variable
set_fact:
ece_nodes: []
- name: Append string to ECE node list
set_fact:
ece_nodes: "{{ ece_nodes + [ item ] }}"
with_items:
- "{{ dp_record | default(None) |
regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
- "{{ iampython_record | default(None) |
regex_replace('-[0-9].[0-9].[0-9].rpm','') }}"
- "{{ iamservice_record | default(None) |
regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
- "{{ iamesa_record | default(None) |
regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
when: item is defined and item != None and item != ""
- name: Display Lists
debug:
msg:
- "{{ ece_nodes }}"
Still i get the same result:
[
"dp-steps-common-3.0.12",
"iam-python-common-1.0.1",
"iam-service-default-3.1.37",
"None"
],
On Wednesday, February 5, 2020 at 10:04:38 PM UTC+5:30, Rakesh Parida wrote:
>
> Hi Vladimir,
>
> I made changes as follows:
> - name: Create an empty list variable
> set_fact:
> ece_nodes: []
>
> - name: Append string to ECE node list
> set_fact:
> ece_nodes: "{{ ece_nodes + [ item ] }}"
> with_items:
> - "{{ dp_record | default(None) |
> regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
> - "{{ iampython_record | default(None) |
> regex_replace('-[0-9].[0-9].[0-9].rpm','') }}"
> - "{{ iamservice_record | default(None) |
> regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
> - "{{ iamesa_record | default(None) |
> regex_replace('-[0-9].[0-9].[0-9][0-9].rpm','') }}"
> - name: Display Lists
> debug:
> msg:
> - "{{ ece_nodes }}"
>
> I still get the same :
> ok: [BVI06CS2] => {
> "msg": [
> [
> "dp-steps-common-3.0.12",
> "iam-python-common-1.0.1",
> "iam-service-default-3.1.37",
> "None"
> ],
>
> If the value is not present it should not be present in the list. Only the
> list should have present items.
> The items which are absent should be not appended.
>
>
>
>
> On Wednesday, February 5, 2020 at 5:52:16 PM UTC+5:30, Vladimir Botka
> wrote:
>>
>> On Wed, 5 Feb 2020 03:52:22 -0800 (PST)
>> Rakesh Parida <[email protected]> wrote:
>>
>> > [...]
>> > with_items:
>> > - "{{ dp_record | default(None) }}"
>> > - "{{ iampython_record | default(None) }}"
>> > - "{{ iamservice_record | default(None) }}"
>> > - "{{ iamesa_record | default(None) }}"
>> >
>> > But when the "iamesa_record" is not present i get the following list
>> Output:
>> > "msg": [
>> > "dp-steps-common",
>> > "iam-python-common",
>> > "iam-service-default",
>> > "None"
>> > ],
>> >
>> > IS there any way that if the item is not available then it should not
>> be
>> > appended to the list.
>>
>> Yes. Test the "item". For example
>>
>> with_items:
>> - "{{ dp_record | default(None) }}"
>> - "{{ iampython_record | default(None) }}"
>> - "{{ iamservice_record | default(None) }}"
>> - "{{ iamesa_record | default(None) }}"
>> when: item
>>
>> I've removed the irrelevant regex_replace part of the filters.
>>
>> HTH,
>>
>> -vlado
>>
>
--
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/9bbd648b-8496-48f1-9004-89718f063073%40googlegroups.com.