in Ansible by
Ansible delegate_to

► Click here to show 1 Answer

0 votes
Delegating a task

Sometimes you want to execute an action on a different system. This could be, for instance, a database node while you are deploying something on an application server node or to the local host. To do so, you can just add the 'delegate_to: HOST' property to your task and it will be run on the proper node. Let's rework the previous example to achieve this:


    - hosts: database

      remote_user: ansible


      - name: Count processes running on the remote system

        shell: ps | wc -l

        register: remote_processes_number

      - name: Print remote running processes


          msg: '{{ remote_processes_number.stdout }}'

      - name: Count processes running on the local system

        shell: ps | wc -l

        delegate_to: localhost

        register: local_processes_number

      - name: Print local running processes


          msg: '{{ local_processes_number.stdout }}'
Learn More with Madanswer

Related questions

0 votes
asked Aug 24, 2019 in Ansible by rahulsharma