• Skip to primary navigation
  • Skip to content
  • Skip to footer
Automate NYC! Let's automate that...
  • Posts
  • Categories
  • Tags
  • KB Docs
    1. Home
    2. /
    3. Ansible
    4. /
    5. How to run task only on the first node in group

    Eric Chong

    Ansible Automation Architect @ Red Hat

    • NYC
    • Website
    • LinkedIn

    How to run task only on the first node in group

    April 4, 2018 less than 1 minute read

    How to run task only on first node in group

    Check the group array

    For example

    - name: Ping first node listed in group "tower"
      ping:
      when: inventory_hostname == groups['tower'][0]
    

    Tags: Ansible, inventory

    Categories: Ansible

    Updated: April 4, 2018

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    Leave a comment

    You may also enjoy

    Use Kerberos for AAP PostgreSQL Connection

    August 9, 2023 2 minute read

    We have Red Hat Identity Management (IdM) setup in the lab to provide Kerberos authentication. This how-to will demonstrate setting up AAP to connect to its...

    Using the ansible.controller credential module

    July 20, 2023 1 minute read

    The awx.awx.credential or ansible.controller.credential cannot see the secret value of existing credential, so it compares other fields in the inputs to dete...

    Launch AAP job via REST API

    July 16, 2023 1 minute read

    We want to launch AAP job from shell script. The job template has Limit, Instance Groups and Variables set with Prompt on launch enabled, so users can provi...

    Seaching a list of dictionay objects where keys name has dots

    February 27, 2023 1 minute read

    We need to search a list of dictionary objects where the key name is dynamic and might have dots (“.”) inside, such as a FQDN hostname.

    • Follow:
    • Feed
    © 2023 Eric Chong. Powered by Jekyll & Minimal Mistakes.