how to access hosts variable in ansible tasks

30 views
Skip to first unread message

Kunalsing Thakur

unread,
Apr 14, 2019, 12:04:45 AM4/14/19
to Ansible Project
  gather_facts: false
  tasks:
  - name: checking uptime for {{ ansible_hostname }}
    command: uptime
    when: ( "slave" in uriresult.content )

Kunalsing Thakur

unread,
Apr 14, 2019, 12:53:07 AM4/14/19
to Ansible Project
One more thing i don't want to use gather_facts: true

Raghavendra Rao

unread,
Apr 14, 2019, 6:13:54 AM4/14/19
to ansible...@googlegroups.com
You can use inventory_hostname.

This takes the name of the hosts as configured in the inventory file.

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ac8fb70f-99cc-4192-b1e4-94dc199964ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kunalsing Thakur

unread,
Apr 14, 2019, 8:54:02 AM4/14/19
to Ansible Project
can you point me to Ansible doc For this also

I need to use only test or test1


On Sunday, April 14, 2019 at 3:43:54 PM UTC+5:30, Raghavendra Rao wrote:
You can use inventory_hostname.

This takes the name of the hosts as configured in the inventory file.

On Sun, 14 Apr 2019, 09:34 Kunalsing Thakur, <bits.k...@gmail.com> wrote:
  gather_facts: false
  tasks:
  - name: checking uptime for {{ ansible_hostname }}
    command: uptime
    when: ( "slave" in uriresult.content )

--
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...@googlegroups.com.

Raghavendra Rao

unread,
Apr 14, 2019, 2:55:18 PM4/14/19
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages