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,890 points
451 views

1 answer to this question.

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,810 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
476 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
175 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
48 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
124 views
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,810 points
4,028 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,810 points
99 views