Based on vendor have to execute playbook

54 views
Skip to first unread message

NAVEEN

unread,
Jun 16, 2021, 8:29:15 PM6/16/21
to ansible...@googlegroups.com
Hello Team ,

I am having 3 vendors Ex :HP ,DELL ,Lenovo 
i have 3 separate  playbooks
Now  i want to execute those  based on vendor .If it is HP it should call Hp Playbook Likewise..Can some one please help.

--
Regards
Naveen 

Wei-Yen Tan

unread,
Jun 16, 2021, 8:33:01 PM6/16/21
to ansible...@googlegroups.com
Use conditionals as in when 


From: ansible...@googlegroups.com <ansible...@googlegroups.com> on behalf of NAVEEN <navee...@gmail.com>
Sent: Thursday, June 17, 2021 12:28:54 PM
To: ansible...@googlegroups.com <ansible...@googlegroups.com>
Subject: [ansible-project] Based on vendor have to execute playbook
 
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAB_%3D4oa%2BVbabwdnAanxWn25SPkK-yaoOpw3eyTP1%2BQXSRdw79g%40mail.gmail.com.

Thanh Nguyen Duc

unread,
Jun 16, 2021, 9:19:30 PM6/16/21
to ansible...@googlegroups.com
You can see the vendor when gather facts and set condition when vendor = hp

Sent from my iPhone

On 17 Jun 2021, at 08:32, Wei-Yen Tan <weiye...@gmail.com> wrote:



Vladimir Botka

unread,
Jun 16, 2021, 9:55:29 PM6/16/21
to NAVEEN, ansible...@googlegroups.com
It's not possible to conditionally run a playbook from another
playbook. Instead, rewrite the playbooks to roles for a
particular HW. For example

shell> cat roles/role2/tasks/main.yml
- debug:
msg: Runing on Dell

The playbook

- hosts: localhost
gather_facts: true
vars:
my_hw: "{{ ansible_system_vendor.split().0 }}"
my_roles:
HP: role1
Dell: role2
Lenovo: role3
tasks:
- debug:
msg: "{{ my_hw }} is in in my_roles: {{ my_hw in my_roles }}"
- include_role:
name: "{{ my_roles[my_hw] }}"
when: my_hw in my_roles

gives

msg: 'Dell is in in my_roles: True'
msg: Runing on Dell


--
Vladimir Botka
Reply all
Reply to author
Forward
0 new messages