Questions tagged [ansible-role]

Ansible role is a set of tasks to configure a host to serve a certain purpose like configuring a service, whereby they are defined using YAML files with a predefined directory structure, as part of the provisioning, configuration management, and application-deployment tool Ansible. Use this tag for questions related to the role tasks in Ansible.

Ansible role is a set of tasks to configure a host to serve a certain purpose like configuring a service, whereby they are defined using YAML files with a predefined directory structure, as part of the provisioning, configuration management, and application-deployment tool Ansible. Use this tag for questions related to the role tasks in Ansible.

173 questions
103
votes
8 answers

Ansible: Can I execute role from command line?

Suppose I have a role called "apache" Now I want to execute that role on host 192.168.0.10 from the command line from Ansible host ansible-playbook -i "192.168.0.10" --role "path to role" Is there a way to do that?
Karl
  • 2,203
  • 5
  • 18
  • 37
21
votes
2 answers

How to split an ansible role's `defaults/main.yml` file into multiple files?

In some ansible roles (e.g. roles/my-role/) I've got quite some big default variables files (defaults/main.yml). I'd like to split the main.yml into several smaller files. Is it possible to do that? I've tried creating the files defaults/1.yml and…
myrdd
  • 2,272
  • 1
  • 17
  • 22
19
votes
1 answer

How to write an Ansible role task that only runs when any of the previous other tasks in the task file have been changed?

I am working on a role where I want one task to be run at the end of the tasks file if and only if any of the previous tasks in that task file have changed. For example, I have: - name: install package apt: name=mypackage state=latest - name:…
rasebo
  • 757
  • 11
  • 20
15
votes
4 answers

Installing NodeJS LTS for Ansible

I'm looking for an appropriate Ansible Role or Ansible YAML file for installing NodeJS LTS on a Ubuntu 16.04.3 xenial system. I tried more than 10 Ansible roles from Galaxy but didn't find any of them working (throws error such as potentially…
Janshair Khan
  • 213
  • 1
  • 2
  • 11
13
votes
1 answer

Where to place requirements.yml for Ansible and use it to resolve dependencies?

I am new to ansible and was exploring dependent roles. documentation link What I did not come across the documentation was- where to place the requirements.yml file. For instance, if my site.yml looks like this: --- - name: prepare system hosts:…
sudeepgupta90
  • 583
  • 1
  • 5
  • 17
12
votes
5 answers

Configure Ansible roles with dependent roles

The problem is best described with an example: There are two roles: mailserver: a basic mail server configuration mailinglist: mailing list application The mailing list software needs the mailserver to transport incoming mails to the mailing list…
Christian
  • 3,152
  • 4
  • 22
  • 26
11
votes
1 answer

How to run only one role of an Ansible playbook?

I have a site.yml which imports several playbooks. - import_playbook: webservers.yml - .... Every playbook "calls" several roles: - name: apply the webserver configuration hosts: webservers roles: - javajdk - tomcat - apache How can…
Michael Hoeller
  • 17,881
  • 7
  • 29
  • 59
8
votes
1 answer

How to automatically install Ansible Galaxy roles, using Vagrant?

Using one playbook only, then it's not possible to have Ansible automagically install the dependent roles. At least according to this SO thread. But, I have the added "advantage" of using Vagrant and Vagrant's Ansible local provisioner. Any tricks I…
Martin Andersson
  • 14,356
  • 8
  • 77
  • 106
7
votes
2 answers

Ansible playbook which uses a role defined in a collection

This is an example of an Ansible playbook I am currently playing around with: --- - hosts: all collections: - mynamespace.my_collection roles: - mynamespace.my_role1 - mynamespace.my_role2 - geerlingguy.repo-remi The…
SpongeBobPHPants
  • 541
  • 5
  • 16
7
votes
3 answers

How can I skip role in Ansible?

I have this playbook: roles: - { role: common} - { role: mariadb} - { role: wordpress} What is want is in every role I want to have first task as some conditional which if true then I want to skip the whole role and playbook continues…
Mr. Mirror
  • 91
  • 1
  • 1
  • 4
5
votes
1 answer

How to wait for ssh to become available on a host before installing a role?

Is there a way to wait for ssh to become available on a host before installing a role? There's wait_for_connection but I only figured out how to use it with tasks. This particular playbook spin up servers on a cloud provider before attempting to…
shellwhale
  • 555
  • 4
  • 22
5
votes
4 answers

How to keep ansible role from running multiple times when listed as a dependency?

We broke down our giant ansible workspace into individual, simple roles that can be run on their own. They all depend on our yum role that provisions repositories, etc, and all the roles (A, B, C) have it listed in their…
user10358840
5
votes
1 answer

What's the difference between roles and tasks (and tags) in Ansible?

I'm finding myself getting confused between roles and tasks all the time. I get that tags are a way to tag individual items, but I'm confused how I'd use them. Let's say I had to do the following Users Create a user named "deploy" Add ssh key…
user2490003
  • 7,930
  • 12
  • 59
  • 115
5
votes
3 answers

Ansible: execute role only for some hosts

Let's say I have a single playbook with some roles for the installation of an appserver and I like to apply the same playbook on both production and testing servers. Both production and testing servers have the same list of roles, with the exception…
tvs
  • 627
  • 1
  • 12
  • 27
5
votes
3 answers

Creating a dynamic role in ansible

After going through several documentation I concluded that, I can't use with_items for roles. So, I created a filter_plugin to generate a list of dictionaries for roles. Here is my Play: --- - name: Boostrap vpc and subnets with route table …
Suku
  • 3,540
  • 19
  • 22
1
2 3
11 12