Using multiple config files using same template in a role in ansible

0 votes

I want to use a role with a template and want to use multiple config wiles with different names and values. I am using the group_vars directory which is on the same level as the playbook which hosts its runs.

Here's my sample playbook

---
- hosts: emea-stg-web
  vars_files:
    - group_vars/ssh_user.yml
  remote_user: "{{ ssh_user }}"
  become_user: root

  roles:
    - nginx-install
    - php5.6-install

I want to have each "item" in the role use different values, like variable "proj" can have values ["pro1","pro2","pro3"] in an iterative way. Any way I store them in a file.

---
- hosts: emea-stg-web
  vars_files:
    - group_vars/ssh_user.yml
  remote_user: "{{ ssh_user }}"
  become_user: root

  roles:
    - nginx-install
      with_items:
      - test1
      - test2
      - test3
    - php5.6-install
Jun 5, 2018 in Ansible by shubham
• 6,560 points
247 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Go through this include_role module:

tasks:
  - include_role:
      role: nginx-install
      vars_from: "{{ item }}"
    with_items:
      - vars_file1
      - vars_file2

Also the group_vars directory is intended to store var files for host groups, so use it for that purpose only.

answered Jun 5, 2018 by DareDev
• 6,670 points

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

Create directories and download files in Ansible using Ansible playbook

Hey @Yash,  you could either use file module ...READ MORE

answered Jan 24 in Ansible by Cerdin
261 views
0 votes
1 answer

Syntax error while using block in ansible role

block should be on the same indentation level ...READ MORE

answered Mar 13 in Ansible by Kim
63 views
0 votes
1 answer

Error while copying files using ansible role.

Add the following as an argument to ...READ MORE

answered Mar 14 in Ansible by Yesha
40 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

ansible playbook: using multiple variables in loops

Use an indexed hostname, and then define ...READ MORE

answered Jul 16, 2018 in Ansible by DareDev
• 6,670 points
3,139 views
0 votes
1 answer

How can I create a new user using ansible ploybook?

You're switching from the root user. Root ...READ MORE

answered Mar 29, 2018 in Ansible by DareDev
• 6,670 points
81 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.