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] <javascript:>> 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/00c29cfd-437e-4d37-b77e-4b4dbd57e4d9%40googlegroups.com.