Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible: call same role with differents vars in a playbook

Tags:

ansible

I try to control from one unique playbook the call of the same role n times with n different vars:

---
- hosts: myhost
  vars:
    user: user1
    virtualenv: venv_nameV3
  roles:
    - makeuser
    - stack  # use virtualenv var so stack role is installed in venv_nameV3      
    - stack  # should need it's own virtualenv value e.g. venv_nameV4
    - stack  # should need it's own virtualenv value e.g. venv_nameV5
    - stack  # should need it's own virtualenv value e.g. venv_nameV6
like image 982
user3313834 Avatar asked Feb 08 '23 14:02

user3313834


1 Answers

You can parameterise roles by adding variables using the following syntax

---
- hosts: myhost
  vars:
    user: user1
    virtualenv: default_venv_name
  roles:
    - makeuser
    - { role: stack, virtualenv: 'venv_nameV3' }
    - { role: stack, virtualenv: 'venv_nameV4' }
    - { role: stack, virtualenv: 'venv_nameV5' }
    - { role: stack, virtualenv: 'venv_nameV6' }
like image 175
Ben Swinburne Avatar answered Mar 05 '23 19:03

Ben Swinburne