I'm new to Ansible too, so take this explanation with a grain of salt!

My understanding of "with_items" is that it takes a list. The loop iterates
over the list, referring to the current element as "item".

So inside your loop, you should refer to "item" (not "items"!)) which on
each iteration will be replaced by the next element from the list called
"dits".

Something like this:

- name: lsvob
    shell: /usr/atria/bin/cleartool lsvob | grep -i {{ item }}
    args:
      chdir: "/home/vobadmin"
    with_items: "{{ dits }}"

I'm not sure what that shell command is doing, so can't comment on whether
it is correct for your purpose.

Regards, K.


On Sun, May 13, 2018 at 7:39 PM, Saranya N <[email protected]> wrote:

> Hi Kai ,
>
> Thankyou for your response but unfortunately it still doesn't work for me.
>
> It still doesn’t work. Sorry, I’m very new to ansible and just started
> working on it.
>
>
>
> I get below error:
>
>
>
> task path: /home/dev_user/ansible_test/ansible_dev/clearcase/
> playbooks/testdump.yml:20
>
> ok: [aaa.com] => {
>
>     "ansible_facts": {
>
>         "localvar": {
>
>             "vobs": [
>
>                 "/project/vob_solaris_test.vbs",
>
>                 "/project/vob_solaris_test22.vbs"
>
>             ]
>
>         }
>
>     },
>
>     "changed": false
>
> }
>
>
>
> TASK [lsvob] ************************************************************
> ************************************************************
> **************************************************************************
>
> task path: /home/dev_user/ansible_test/ansible_dev/clearcase/
> playbooks/testdump.yml:32
>
> fatal: [aaa.com]: FAILED! => {
>
>     "failed": true,
>
>     "msg": "the field 'args' has an invalid value, which appears to
> include a variable that is undefined. The error was: 'items' is
> undefined\n\nThe error appears to have been in '/home/dev_user/ansible_test/
> ansible_dev/clearcase/playbooks/testdump.yml': line 32, column 5, but
> may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe
> offending line appears to be:\n\n\n  - name: lsvob\n    ^ here\n"
>
> }
>
>         to retry, use: --limit @/home/dev_user/ansible_test/
> ansible_dev/clearcase/playbooks/testdump.retry
>
>
>
> PLAY RECAP ************************************************************
> ***************************************************************
>
> aaa.com       : ok=3    changed=2    unreachable=0    failed=1
>
>
>
>
>
>
>
>
>
> my playbook lokks like below:
>
> ---
>
> - hosts: sol
>
>   become: yes
>
>   become_method: su
>
>   become_user: vobadmin
>
>   gather_facts: no
>
>
>
>   tasks:
>
>
>
>   - name: Load the variables
>
>     include_vars:
>
>      file: /home/a594588/ansible_test/ansible_dev/clearcase/
> inventories/NP/voblist.yml
>
>      name: localvar
>
>
>
>   - name: lsvob
>
>     shell: /usr/atria/bin/cleartool lsvob | grep -i {{ items }}
>
>     args:
>
>       chdir: "/home/vobadmin"
>
>     with_items: "{{ dits }}"
>
>
>
>
>
> I changed the contents of the include_vars file input file:
>
>
>
> cat /home/devuser/internproj/inventories/NP/voblist.yml
>
>
>
> dits:
>
>
>
> - /project/vob_solaris_test.vbs
>
> - /project/vob_solaris_test22.vbs
>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/82f6779b-c698-44f0-81b5-37de10960a4c%40googlegroups.
> com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Karl Auer

Email  : [email protected]
Website: http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2B%2BT08T_jCcDwSUkREypmm6zmQX0J5VucoJe7ZHhq%2Bsw899TAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to