Hi Team, I have changed to standard jinja2 template , even then the error is same. It fails to find xvdb but it finds xvda2 . The syntax to extract UUID is same and both values are present in the ansible localhost -m setup command output . This playbook is running on localhost only.
``` UUID={{ ansible_facts['device_links']['uuids']['xvda2'][0] }} / {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 UUID_home={{ ansible_facts['device_links']['uuids']['xvdb'][0] }} /home {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 UUID_var={{ ansible_facts['device_links']['uuids']['xvdc'][0] }} /var {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 UUID_swap={{ ansible_facts['device_links']['uuids']['xvdd'][0] }} swap swap defaults 0 0 ``` Regards Sachin Kumar On Thursday, May 18, 2023 at 11:42:51 AM UTC+5:30 Sac Isilia wrote: > Hi Team, > > The standard way to access is - > ansible_facts['device_links']['uuids']['xvdb'][0] . It works on existing > rhel 7 machine but it fails there. Also if the syntax is wrong it should > have failed at xvda2 line , the very first line of jinja2 template. WHy it > failed at second line ? That's strange . What should be the correct way to > extract uuid that works in jinja2 template. > > Regards > Sachin Kumar > > On Thursday, May 18, 2023 at 11:24:48 AM UTC+5:30 Dick Visser wrote: > >> On Thu, 18 May 2023 at 03:14, Sac Isilia <udayprata...@gmail.com> wrote: >> >>> Hi Team, >>> >>> Below is the jinja template that I wrote that works fine on existing >>> RHEL 7 machine . >>> >>> ``` >>> UUID={{ >>> hostvars['localhost']['ansible_facts']['device_links']['uuids']['xvda2'][0] >>> }} / {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 >>> >> >> >> >>> UUID_home={{ >>> hostvars['localhost']['ansible_facts']['device_links']['uuids']['xvdb'][0] >>> }} >>> >> >> >> >> /home {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 >>> UUID_var={{ >>> hostvars['localhost']['ansible_facts']['device_links']['uuids']['xvdc'][0] >>> }} /var {{ ansible_facts['mounts'][0].fstype }} defaults 0 0 >>> UUID_swap={{ >>> hostvars['localhost']['ansible_facts']['device_links']['uuids']['xvdd'][0] >>> }} swap swap defaults 0 0 >>> ``` >>> >>> It works fine on existing test RHEL 7 machine but it fails when I am >>> trying to run this template in our Jenkins job with below error. >>> >>> ``` >>> An exception occurred during task execution. To see the full traceback, >>> use -vvv. The error was: AnsibleUndefinedVariable: 'dict object' has no >>> attribute 'xvdb' >>> ``` >>> >>> I tried running ansible localhost -m setup and the above paths actually >>> exist and xvdb entry is also there. My main doubt is the playbook parsed >>> xvda2 line but fails at xvdb. Why? Below is the relevant output of ansible >>> setup command. >>> >>> ``` >>> >> >> >> \"ansible_device_links\": {", >>> >> >> This is different from what you have in the template: >> >> hostvars['localhost']['ansible_facts']['device_links'] >> >> Also are you sure this "Jenkins" is targeting the right host? That could >> be the problem. >> >> >> >> >>> " \"ids\": {}, ", >>> " \"labels\": {}, ", >>> " \"masters\": {}, ", >>> \"uuids\": {", >>> \"xvda2\": [", >>> \"87be522b-2b75-4150-879d-4ee109559f7e\"", >>> ], ", >>> \"xvdb\": [", >>> \"da750c25-cc98-4c2a-a5fe-24bbf42c210e\"", >>> " ], ", >>> " \"xvdc\": [", >>> " \"c2d5f1dc-5840-40bf-9a54-bb8fb215fbec\"", >>> " ], ", >>> " \"xvdd\": [", >>> " \"3b78b0ff-cc18-49ff-80b4-f21ca0a1234e\"", >>> " ]", >>> " }", >>> " }, ", >>> ``` >>> >>> Please help me to resolve this >>> >>> Regards >>> Sachin Kumar >>> >>> -- >>> 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 ansible-proje...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ansible-project/52ff8092-399f-48ab-901a-228ce8c16c0cn%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/ansible-project/52ff8092-399f-48ab-901a-228ce8c16c0cn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> Sent from Gmail Mobile >> > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8cfbcb1e-047f-4ac9-b3ab-d277dc9b2411n%40googlegroups.com.