Score:1

Ansible run a task on a different host than local

kr flag

I have an ansible playbook which runs on localhost. I need to run a particular task which is invoked inside my playbook on a different host (different group). Is this possible to speicify within the task that this task should use a different connection as opposed to the local which is used by all other tasks and roles?

role1: (runing on localhost)
- task1
- task2
- include_role:role2
  tasks_from: task4 (should run on controllergroup)
role2:
- task4
- task5

Is it possible to achive this scenario without invoking two ansible playbooks?

This is part of a jenkins job and i do two triggers to invoke the ansible playbooks separately, which i want to do within the role1

Score:1
br flag

Q: "Is it possible to achieve this scenario without invoking two ansible playbooks?"

A: Yes. It's possible. Split the playbook into plays, e.g.

- hosts: localhost
  tasks:
    - include_role:
        name: role1
        tasks_from: task1
    - include_role:
        name: role1
        tasks_from: task2
- hosts: controllergroup
  tasks:
    - include_role:
        name: role2
        tasks_from: task4
- hosts: localhost
  tasks:
    - include_role:
        name: role2
        tasks_from: task4
    - include_role:
        name: role2
        tasks_from: task5
br flag
See [What are comments for, and when shouldn't I comment?](https://meta.stackexchange.com/questions/19756/how-do-comments-work)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.