how to access hosts variable in ansible tasks

  • hosts: test.example.com, test1.example.com
    gather_facts: false
    tasks:
  • name: checking uptime for {{ ansible_hostname }}
    command: uptime
    when: ( “slave” in uriresult.content )

One more thing i don’t want to use gather_facts: true

You can use inventory_hostname.

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

can you point me to Ansible doc For this also

I need to use only test or test1

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables