0
votes

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"       
1
With import_playbook any combination of roles and hosts is possible.Vladimir Botka
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

1 Answers

-1
votes

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.