0

Scenario
I have a group A in my inventory, where A contains a1,a2,a3 hosts. It does mean that I can write in my playbook X.yml:

- hosts: A
  roles:
    - role:
      name: r

The problem is about playbook X is started with limited number of hosts, namely launch of ansible-playbook X is limited to host a1. This playbook X invoke role r (which is executed on host a1). I wouldn't like to change this behaviour (in other words I would like to preserve this limitation, don't ask why please).

Question
Is it possible to write task in role r in such way that it will be executed on all hosts from group A even if playbook is limited to host a1? Please keep in mind that my inventory contains group A.

If not, could you suggest me another approach?
The one that I can do is:

- hosts: A
  tasks:
    - name: "This task"       
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Tom
  • 7
  • 6
  • With [import_playbook](https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html#import-playbook-import-a-playbook) any combination of roles and hosts is possible. – Vladimir Botka May 15 '19 at 17:08
  • If you are running ansible with `--limit`, I don't think you can get it to execute on any hosts that are not part of the current limit configuration. – larsks May 15 '19 at 18:33

1 Answers1

0

I do not know for certain, but this might work:

- name: Run task on hosts in group A
  some_random_module:
    var1: value1
    var2: value2
  delegate_to: "{{ item }}"
  with_items: "{{ groups['A'] }}"

No promises.

Jack
  • 5,801
  • 1
  • 15
  • 20