user13708337
user13708337

Reputation: 129

How to reuse Ansible role with different set of variables in the same playbook

I want to invoke the same role twice with different set of variables. However, when I run the playbook, the first instance of role is executed, the second call is ignored.

The details are as follows.

---
- hosts: server
  gather_facts: true

  roles:
    - role: upgrade_opatch_utility
      vars:
        source: /u1/software/OPatch
        opatch_file_name: p6880880_200000_Linux-x86-64.zip
        oracle_home: /u1/app/oracle/product/19.3.0/dbhome_1
        
    - role: upgrade_opatch_utility
      vars:
        source: /u1/software/OPatch
        opatch_file_name: p6880880_200000_Linux-x86-64.zip
        oracle_home: /u1/app/oracle/product/12.2.0/dbhome_1 

How can I re arrange the roles invocation multiple times with different set of variables?

Thanks in advance.

FR

Upvotes: 1

Views: 1291

Answers (1)

micke
micke

Reputation: 1048

Set a different name for each role invocation. That way Ansible won't consider them duplicates.

roles:
- name: upgrade_opatch_19
  role: upgrade_opatch_utility
  vars:
[...]
- name: upgrade_opatch_12
  role: upgrade_opatch_utility
  vars:
[...]

Upvotes: 3

Related Questions