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
• 7,340 points
4,222 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,890 points

Related Questions In Ansible

0 votes
1 answer

How to add multiple lines in a file using Ansible playbook?

Hi@akhtar, You can update your file using lineinfile ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,460 points
26,629 views
0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
4,155 views
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, 2019 in Ansible by Cerdin
5,941 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, 2019 in Ansible by Kim
4,487 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,034 views
+2 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,890 points
18,986 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,890 points
899 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP