Hello

- debug:
     var: hostvars

shows all the hosts in my inventory file, so I believe my playbook has
access to all hosts. To hash out issue with inventory file, I modified my
code as below.

------------------

- hosts: *hostname2*
  tasks:
    -
      file:
       path: "/home/ansible_user/from_controller3/file_name"
       state: touch
      when: "hostvars['*hostname2*']['ansible_facts']['distribution'] ==
'CentOS'"

---------------------

*hostname2 *is mentioned near hosts and near when. I still get following
error

--------------
FAILED! => {"msg": "The conditional check
'hostvars['hostname2']['ansible_facts']['distribution'] == 'CentOS''
failed. The error was: error while evaluating conditional
(hostvars['hostname2']['ansible_facts']['distribution'] == 'CentOS'):
\"hostvars['hostname2']\" is undefined

--------------

Any thoughts ?


On Tue, Oct 1, 2019 at 5:00 PM Vladimir Botka <vbo...@gmail.com> wrote:

> > > > > > *Trial1* :
> > > > > > when: {{hostvars['hostname1]['ansible_facts']['distribution']}}
> ==
> > > > > > "CentOS"
> > > > >
> > > > > Try this one
> > > > > when: "hostvars['hostname1']['ansible_facts']['distribution'] ==
> > > > > 'CentOS'"
> > >
> > > On Tue, 1 Oct 2019 12:41:22 +0530
> > > Srinivas Naram <srinivas.nar...@gmail.com> wrote:
> > > > I have tried with your suggestion and got following error.
> > > > fatal: [172.19.251.173]: FAILED! => {"msg": "The conditional check
> > > > 'hostvars['hostname1']['ansible_facts']['distribution'] == 'CentOS''
> > > > failed. The error was: error while evaluating conditional
> > > > (hostvars['hostname1']['ansible_facts']['distribution'] == 'CentOS'):
> > > > \"hostvars['hostname1']\" is undefined\n\n
>
> > > Don't use undefined hostnames.
>
> On Tue, 1 Oct 2019 14:44:59 +0530
> Srinivas Naram <srinivas.nar...@gmail.com> wrote:
> > hostname1 is defined in my inventory file. Here is the yml file snippet
> >
> > - hosts: hostname2
> >   gather_facts: true
> >   tasks:
> >     -
> >       file:
> >        path: "/home/ansible_user/controller3/file_name"
> >        state: touch
> >       when: "hostvars['hostname1']['ansible_facts']['distribution'] ==
> > 'CentOS'"
> > When I comment'when'this code runs fine. Please suggest.
>
> The playbook is running at 'hostname2' only and knows nothing about
> 'hostname1' at all. You might want to take a look at
>
>     - debug:
>         var: hostvars
>
> Cheers,
>
>         - 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAG-N3P5E7tbyJHedA-kHp9PbU4rjgXneCF31N%2BKgnQ6HdRrzoA%40mail.gmail.com.

Reply via email to