Thank you Brian for your reply.
Based on your suggestions, i created this playbook:
(create two groups and then apply the role to each subset)
- hosts: all
remote_user: root
gather_facts: false
tasks:
- ping:
register: rootlogin
ignore_errors: true
- group_by: key=fedora-user
when: rootlogin|failed
- group_by: key=root-user
when: rootlogin|success
- name: Execute play for CentOS instances
hosts: root-user
remote_user: root
roles:
- { role: path/to_role }
- name: Execute play for Fedora instances
hosts: fedora-user
remote_user: fedora
sudo: yes
sudo_user: root
roles:
- { role: path/to_role }
The problem is that only the root-user group it is created.
created 'group_by' ActionModule: key=stage-root-user
No fedora-user group was created. When it comes the time to execute the rol
for the fedora instances.
skipping: no hosts matched
I did also tried, create the two groups using multi plays(same idea), but
the groups were created with the same elements:
- name: Group CentOS instances
hosts: all
remote_user: root
gather_facts: no
# ignore_errors: true
tasks:
- name: remote_user is root
group_by: key=root_user
ignore_errors: true
- name: Group Fedora instances
hosts: all
gather_facts: no
remote_user: fedora
sudo: yes
sudo_user: root
tasks:
- name: remote_user is fedora
group_by: key=fedora_user
ignore_errors: true
- name: Execute play for CentOS instances
hosts: root_user
remote_user: root
roles:
- { role: path/to_role }
- name: Execute play for Fedora instances
hosts: fedora_user
remote_user: fedora
sudo: yes
sudo_user: root
roles:
- { role: path/to_role }
FATAL: no hosts matched or all hosts have already failed -- aborting
Thank you!
Ansible 1.9
On Friday, July 10, 2015 at 4:28:36 PM UTC-5, Brian Coca wrote:
>
> There are several ways, the easiest is if your inventory script
> provides OS info:
>
> remote_user: "{{ansible_distibution == 'Fedora'|ternary('fedora', 'root')
>
> If you have no info ahead of time you can test connecting and then use
> group_by (example below) or the same expression above on the result
> var. If using group_by you can preset group_vars/fedora =>
> ansible_ssh_user: fedora
>
> - hosts: all
> remote_user: root
> gather_facts: False
> tasks:
> - ping:
> register: rootlogin
> ignore_errors: yes
>
> - group_by: key=fedora
> when: rootlogin|failed
>
> --
> Brian Coca
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3da95f00-b712-4745-8498-983cbaf365ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.