On Thu, 17 Jun 2021 05:58:54 +0530
NAVEEN <[email protected]> wrote:

> 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.

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

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20210617035511.63b7d568%40gmail.com.

Attachment: pgpslGYCdj2Db.pgp
Description: OpenPGP digital signature

Reply via email to