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
2
votes
1 answer

How to execute a specific task as an unpriviliged user from an Ansible role when connecting as root

I tried to use the escalation feature of Ansible to run a specific task within a role as an unprivliged user, but the task still executed by the root user with which I execute my playbook calling the role. My problem is related to the creation of a…
2
votes
1 answer

Always run ansible role before other role

I'm trying to find my way out of a dependency thicket. I'm using Ansible 1.9.2. In a single playbook, I want to be able to install a Galaxy role (in the event, the Datadog.datadog role) and configure it. But Ansible always barfs; since the…
maxn
  • 21
  • 4
1
vote
2 answers

Ansible role to filter host based on host variables

I am trying to create a ansible role which filter out host based on dictionary(passed to role) in comparison with host variables. If host variables contains key:value from dictionary it will added to filtered_host list. This is what I found till…
1
vote
2 answers

How to mark an Ansible Role in a Collection as deprecated?

I manage an Ansible Collection on Ansible Galaxy with multiple roles in it and want to mark some of those roles as deprecated. How can I do this? In the Ansible documentation there is only a solution for modules. Can this be adopted to the roles?
1
vote
0 answers

Ansible: idiomatic way to expose different functionalities with one role

I'm writing Ansible roles, one role per 'service' / part of infrastructure that I'm managing. Let's say that' I'm managing some webserver, which is a part of a larger system. The whole system is managed by several playbooks, one each for deploying…
andrejr
  • 133
  • 6
1
vote
1 answer

Naming variables in Ansible roles

In Ansible roles you can define variables in different ways: in vars/main.yml in defaults/main.yml via register in a task via a set_fact task in task vars probably more... Through this answer I came across the recommendation to use a naming…
1
vote
2 answers

Ansible Skip Host For a Specific Role

I have a hosts file that looks a bit different for prod and test and here they are: # Contains the host mappings [master] local-machine ansible_host=192.168.0.201 host_alias=local-machine [node] n1.com ansible_host=192.168.0.202…
joesan
  • 13,963
  • 27
  • 95
  • 232
1
vote
3 answers

Avoid using when condition for each task, while including an Ansible validation role?

I have the following roles structure: $ tree roles roles ├── user │   └── tasks │   └── main.yaml └── validation └── tasks └── main.yaml My goal is to include the validation role into multiple roles and avoid using a when condition,…
Floren
  • 113
  • 11
1
vote
1 answer

Ansible Naming Rules for Roles and Collections (dash, underscore)

Does Ansible have naming rules for roles and collections regarding the use of - (dash) and _ (underscore)? I noticed that since around 2019, geerlingguy only uses underscores for role names (snake_case), but the names of his older roles contain…
phanaz
  • 1,188
  • 8
  • 17
1
vote
2 answers

ansible - how to define var's value depending on ansible_facts

I'm writing an ansible playbook for installing jdk. The logic is to use version 8 if the system is "Ubuntu", but 1.8.0 if it is "CentOS". following is my code: - hosts: all vars: - java_open_jdk_version_major: 8 when:…
Cherie
  • 31
  • 1
  • 5
1
vote
2 answers

Ansible - Set variable based on condition

I have a role called kernel. In its vars file kernel/vars/main.yml, is it possible to set the values of variables based on a condition? For example, say I have a playbook like this that calls my kernel role: --- - hosts: webservers roles: -…
jessefournier
  • 181
  • 1
  • 2
  • 13
1
vote
1 answer

How to access ansible facts in roles?

I am currently working on some ansible automation tasks and wanted to use ansible facts in a role I created. However, I cannot access any facts. Example: If I want to use the default IP-Address of a Windows machine, I was advised to use the…
ActualChipmunk
  • 35
  • 1
  • 1
  • 4
1
vote
1 answer

How to put pause between ansible roles

Here is my playbook: --- - hosts: "mms" user: wladmin roles: - { role: App1 } - { role: App2 } - { role: App3 } - { role: App4 } I wish to put pause of 30 seconds between these ansible roles. I tried the below but it give me…
Ashar
  • 2,942
  • 10
  • 58
  • 122
1
vote
1 answer

Ansible-playbook search for roles in the wrong directory! How to correct it?

When I run the following ansible command: $ ansible-playbook deploy/solo/wifi.yml -i inventories/solo I got the following error message: ERROR! the role 'solo/controller/wifi' was not found in…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
1
vote
2 answers

Ansible user deployment task with loop

I have started an ansible role for user deployment and created some variables in defaults/main.yml: bootstrap_users: - name: test1 comment: "test user 1" shell: "/bin/bash" password: "" groups: [] sshpubkey: "
Andre
  • 39
  • 4