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.

224 questions
132
votes
9 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,903
  • 5
  • 27
  • 43
33
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
  • 3,222
  • 2
  • 22
  • 22
28
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
  • 957
  • 1
  • 13
  • 21
26
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
  • 753
  • 1
  • 9
  • 17
21
votes
4 answers

How to measure and display time taken for tasks when running ansible-playbook?

I have one playbook and in this playbook, there are so many tasks. I need to know which task has taken how much time? Is there any solution?
Dharti Sutariya
  • 419
  • 1
  • 5
  • 14
21
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
  • 293
  • 1
  • 3
  • 11
17
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
  • 22,018
  • 10
  • 39
  • 66
16
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
  • 4,042
  • 4
  • 26
  • 28
11
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
  • 641
  • 7
  • 19
11
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
9
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
  • 18,072
  • 9
  • 87
  • 115
8
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
  • 10,706
  • 17
  • 79
  • 155
8
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
  • 95
  • 1
  • 1
  • 4
8
votes
1 answer

Ignore case sensitivity in Ansible when condition?

I am trying to create an ansible role that depends on other roles only if the hostname of the machine it's being run on contains a certain string. For example: dependencies: - { role: example-role, when: "'hostname' in ansible_hostname" } As it…
Michael
  • 81
  • 1
  • 1
  • 3
7
votes
4 answers

Install multiple yum packages on Centos(node) via Ansible?

Here is the part of YAMLcode that i am trying to run on a node which has operating system, Centos-7...... file hierarchy is --> roles/install_tools/tasks/main.yml its not working fine, YAML syntax is also valid and correct ! Could someone help me…
Saad
  • 916
  • 1
  • 15
  • 28
1
2 3
14 15