1

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

2 Answers 2

1

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
1
0

I suggest you have a look at the earlier question https://stackoverflow.com/questions/32627624/ansible-how-to-run-task-on-other-host-inside-one-playbook

https://medium.com/opsops/ansible-2-5-delegate-to-and-include-role-20cd7e67008e may also be of help to you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .