this is now my jinja, what example did you gave?? I might miss it..
############################################################
DISK1={{ ansible_devices.sda.partitions.sda1.size | default('Not Defined')
}}
DISK2={{ ansible_devices.sdb.partitions.sdb1.size | default('Not Defined')
}}
############################################################
And is still throwing error...
TASK [Template]
****************************************************************
fatal: [server1]: FAILED! => {"changed": false, "msg":
"AnsibleUndefinedVariable: 'dict object' has no attribute 'sdb'"}
PLAY RECAP
********************************************************************
On Thursday, January 14, 2021 at 2:59:30 PM UTC-6 [email protected] wrote:
> On 1/14/21 9:56 PM, ursa Brown wrote:
> > Please remember, some of the server has sdb define, some just sda. I
> still want my playbook to run, The playbook works
> > well if there is sdb.
> >
> > TASK [Template]
> ****************************************************************
> > fatal: [server1]: FAILED! => {"changed": false, "msg":
> "AnsibleUndefinedVariable: 'dict object' has no attribute 'sdb'"}
> >
>
> I already gave you an example which covered both cases.
>
> Regards
> Racke
>
> >
> > On Thursday, January 14, 2021 at 11:27:59 AM UTC-6 [email protected]
> wrote:
> >
> > On 1/14/21 6:20 PM, ursa Brown wrote:
> > > Same error, it will still look for the sdb..
> > >
> > > fatal: [server1]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string:
> > unexpected
> > > '}', expected ')'. String: ARCH={{ ansible_architecture }}\nalias={{
> ansible_default_ipv4.alias }}\nDISK1={{
> > > ansible_devices.sda.partitions.sda1.size }}\nDISK2={{
> ansible_devices.sdb.partitions.sdb1.size | default('Not
> > Defined'
> > > }}\n\n"}
> > >
> >
> > No, you did not copy my example correctly.
> >
> > DISK2={{ ansible_devices.sdb.partitions.sdb1.size | default('Not
> Defined' }}
> >
> > The closing ) is missing in your template.
> >
> > Regards
> > Racke
> >
> > >
> > > On Thursday, January 14, 2021 at 10:54:42 AM UTC-6 [email protected]
> wrote:
> > >
> > > On 1/14/21 1:34 PM, ursa Brown wrote:
> > > > How can it continue the playbook and if disk2 is not there it will
> just put not define. and get all the values.
> > > >
> > > > On Wednesday, January 13, 2021 at 8:39:22 PM UTC-6 ursa Brown wrote:
> > > >
> > > > *******************************
> > > > ---
> > > > - hosts: all
> > > > name:
> > > > become: yes
> > > > tasks:
> > > >
> > > > - name: Template
> > > > template:
> > > > src: disk.j2
> > > > dest: /tmp/mydisk
> > > > ignore_error: True
> > > > *******************************
> > > > Jinja Template
> > > > ARCH={{ ansible_architecture }}
> > > > alias={{ ansible_default_ipv4.alias }}
> > > > DISK1={{ ansible_devices.sda.partitions.sda1.size }}
> > > > DISK2={{ ansible_devices.sdb.partitions.sdb1.size }}
> > >
> > > Please try the following:
> > >
> > > ARCH={{ ansible_architecture }}
> > > alias={{ ansible_default_ipv4.alias }}
> > > DISK1={{ ansible_devices.sda.partitions.sda1.size | default('Not
> Defined')}}
> > > DISK2={{ ansible_devices.sdb.partitions.sdb1.size | default('Not
> Defined')}}
> > >
> > > Regards
> > > Racke
> > >
> > > >
> > > > Expected Output: If Disk1 and Disk 2 is available
> > > > ###############
> > > > cat /tmp/mydisk
> > > > ARCH=x86_64
> > > > alias=ens192
> > > > DISK1=1.00 GB
> > > > DISK2=762.00 MB
> > > > ###############
> > > >
> > > > Expected Output if Disk2 is not available.
> > > > ###############
> > > > cat /tmp/mydisk
> > > > ARCH=x86_64
> > > > alias=ens192
> > > > DISK1=1.00 GB
> > > > DISK2=Not Defined
> > > > ###############
> > > > Reply all
> > > > Reply to author
> > > > Forward
> > > >
> > > > --
> > > > 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] <mailto:
> [email protected]>.
> > > > To view this discussion on the web visit
> > > >
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com
> >
> > > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com
> >>
> > > >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com?utm_medium=email&utm_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com?utm_medium=email&utm_source=footer
> >
> >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com?utm_medium=email&utm_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/57531664-ba31-49fc-b573-c20082fcabc6n%40googlegroups.com?utm_medium=email&utm_source=footer
> >>>.
> >
> > >
> > >
> > >
> > > --
> > > Ecommerce and Linux consulting + Perl and web application programming.
> > > Debian and Sympa administration. Provisioning with Ansible.
> > >
> > > --
> > > 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] <mailto:
> [email protected]>.
> > > To view this discussion on the web visit
> > >
> https://groups.google.com/d/msgid/ansible-project/222abdaa-cffb-4fb6-b51e-5457e54c28a5n%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/222abdaa-cffb-4fb6-b51e-5457e54c28a5n%40googlegroups.com
> >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/222abdaa-cffb-4fb6-b51e-5457e54c28a5n%40googlegroups.com?utm_medium=email&utm_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/222abdaa-cffb-4fb6-b51e-5457e54c28a5n%40googlegroups.com?utm_medium=email&utm_source=footer
> >>.
> >
> >
> >
> > --
> > Ecommerce and Linux consulting + Perl and web application programming.
> > Debian and Sympa administration. Provisioning with Ansible.
> >
> > --
> > 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] <mailto:
> [email protected]>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/e27e9b99-fcbd-44d0-a676-80d39bbb755cn%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/e27e9b99-fcbd-44d0-a676-80d39bbb755cn%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
>
--
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/2e6db3f1-f84f-48f0-bec1-2091a020ca31n%40googlegroups.com.