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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
101 views

Ansible: best way to handle default variables in a collection

I've written an ansible script to install a web application made of several components. While I've originally written it as a collection of several roles, I'm wondering whether this is the best way to ...
Perdu's user avatar
  • 186
1 vote
2 answers
365 views

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 ...
DrunkenAvenger's user avatar
1 vote
2 answers
172 views

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 ...
Hunter's user avatar
  • 23
1 vote
0 answers
55 views

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 ...
andrejr's user avatar
  • 133
2 votes
1 answer
671 views

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 ...
stackprotector's user avatar
0 votes
0 answers
16 views

Ansible cannot find the requested handler that is within the same role [duplicate]

I am running a playbook that includes a role with the roles: key. When a task within the role notifies a handler within the role it throws the following error. ERROR! The requested handler 'Build ...
Braedon's user avatar
  • 61
2 votes
1 answer
1k views

Ansible Molecule ignores collection requirements

I like to use a git based Ansible Collection with my role and try to test that role with molecule. But when I run molecule, there isno output showing me, it is adding that collection nor it find the ...
TRW's user avatar
  • 896
-1 votes
1 answer
168 views

Multiple remote users to work with ansible dynamic inventory

I am using dynamic inventory and i didn't find anything about how to run a playbook with more than one user. When i configure a specific remote user in my ansible.cfg file, the ssh connection works ...
Diana's user avatar
  • 1
2 votes
1 answer
222 views

Print role name of the caller role in Ansible

How to print caller role name from within another role? Playbook: - name: print calling role name hosts: all tasks: - import_role: name: role2 tasks_from: update role2/tasks/...
user592748's user avatar
  • 1,204
0 votes
2 answers
321 views

Ansilbe Playbook Tasks Running Twice

I've spent an obscene amount of time trying to get this playbook/role to work correctly. When I use the tags I've assigned the tasks in the playbook it runs the tagged task and then all the tasks. I ...
cubezombie's user avatar
0 votes
1 answer
302 views

How to list files in an ansible role folder

I'm struggling to get a list with all files under a subfolder of templates role folder using the find module, So to use it afterwards and delete all remote files which are not included in my role ...
Manos K's user avatar
  • 23
1 vote
2 answers
340 views

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....
joesan's user avatar
  • 14.3k
1 vote
3 answers
166 views

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 ...
Floren's user avatar
  • 133
2 votes
1 answer
1k views

Execute Ansible reboot with handler only when required

I have the following file structure: $ tree roles/os roles/os ├── handlers │   └── main.yaml └── tasks └── main.yaml tasks/main.yaml: --- - name: Upgrade all packages ansible.builtin.apt: ...
Floren's user avatar
  • 133
-1 votes
1 answer
167 views

how to use conditional statement in main.yml in ansible roles

I wanna apply role using conditional statement by centos version(7, 8) in yml There are tons of examples of conditional statement in the playbook. However, there seems to be no example of yml to be ...
S.Kang's user avatar
  • 581
0 votes
4 answers
565 views

ansible : replace line in file with new values depending of original values

With loop or other, I can't see how to use the replace or inline module to achieve that. The orinal file contains this line goals first_goal + second_goal I only want to modify the line starting with ...
troubadour's user avatar
0 votes
1 answer
401 views

Ansible - passing a var if it exists

I am running an ansible playbook like this: ansible-playbook -i inventory/inventory1.yml playbooks/playbook1.yml --extra-vars "environment=my_env var=my_var" My inventory1.yml looks ...
fr0zt's user avatar
  • 743
0 votes
0 answers
592 views

How do I download a specific file from GitHub in an Ansible role?

I have a YAML file filled with variables that I need to download with an Ansible role and this file lives within GitHub. In a temporary hacky way I first run a curl command to get the download URL ...
agw2021's user avatar
  • 296
3 votes
1 answer
3k views

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 (...
phanaz's user avatar
  • 1,243
0 votes
1 answer
681 views

Install a specific version of a role with Ansible Galaxy

I'm installing an ansible role with: ansible-galaxy install geerlingguy.java But this command install the latest version. I need to install an old version like: ansible-galaxy install geerlingguy....
Manel's user avatar
  • 1
0 votes
0 answers
175 views

Ansible - recursive argument_spec

I'm trying to create a role with argument validation via the meta/arguments_spec.yml file, and I'd like a user to be able to pass in a tree of arbitrary depth as one of the arguments. In other words, ...
user3781737's user avatar
2 votes
1 answer
4k views

'dict object' has no attribute 'stdout_lines'

I am trying to extract the status (http) (Enabled/ Disabled) for each server and display it in the logs. It is able to check for http status but when I try to store it, it is giving following error. -...
raptor85's user avatar
  • 125
1 vote
2 answers
4k views

Ansible can't find roles from collection

I got collection that has structure namespace/ ── collectionA/ ├── docs/ ├── galaxy.yml ├── README.md └── roles/ ├── roleA/ | └── tasks/ | ├──taskA....
darvark's user avatar
  • 324
2 votes
1 answer
288 views

Pass Ansible variables into custom Ansible module

I have a custom module that resides in the library/ directory of my Ansible role. I can call the module from within my playbook, and the code executes correctly, but only if the values it expects are ...
GreNIX 's user avatar
0 votes
1 answer
210 views

How can I avoid getting a .travis.yml file automatically created inside my ansible role?

I have created several roles with ansible-galaxy init my_role and after a while I realized a .travis.yml file was created automatically for a basic syntax testing. I am not planning to use Travis CI, ...
RicHincapie's user avatar
  • 3,463
0 votes
2 answers
762 views

run ansible role with specific playbook

I have one ansible role with this structure: ── prepare-workstation.yaml ── group_vars └── roles ├── build-nginx-proxy │   ├── defaults │   ├── tasks │   └── templates │ └── ...
pyramid13's user avatar
  • 264
0 votes
1 answer
424 views

Sorting of strings variable in ansible playbook and display result in asending order

I have list of variable like, item-1, item-22, item-3, item-99 i need to display as result of ansible playbook in following form item-1, item-3, item-22, item-99. I tried with below syntax but no luck....
omankame's user avatar
6 votes
1 answer
2k views

How to use a different entry point in ansible roles

Based on ansible documentation for roles I can make multiple role entry points by creating files: playbooks/roles/my_role/tasks/main.yml playbooks/roles/my_role/tasks/other.yml And I can add the ...
HubertNNN's user avatar
  • 1,807
0 votes
1 answer
205 views

How to create a mail profile in my remote windows machine using ansible

I'm unable to create a mail profile in my remote windows machine which has Outlook 2016. I havw to create it using ansible. I tried this: - name: Manage windows server hosts: win tasks: - name:...
user avatar
4 votes
2 answers
1k views

Ansible: how to achieve idempotence with tasks that append files on host (w/o reverting to initial state)

I am having a hard time getting to know how to create Ansible roles that are following the best practices according to documentation. The following use-case which I am looking at is e.g. enabling ...
gczarnocki's user avatar
0 votes
1 answer
5k views

How to check if a directory exists in Ansible playbook level(not in host) from within a role?

I have 2 ansible roles. rundeck_install rundeck_app rundeck_install role install the rundeck community edition. rundeck_app role installs jdk, mysql and rundeck(by using therundeck_install role) ...
anunaki's user avatar
  • 1,244
0 votes
1 answer
95 views

Unable to set multiple conditions in when clause for ansible roles

My ENV is DEV while the instance_name is myapp44 Thus, i want the role for myapp7 to skip as the when condition fails. Below is my role that works fine and skips as the when clause fails. - { role: ...
Ashar's user avatar
  • 3,037
0 votes
1 answer
613 views

About enable/disable by conditional values in ansible yaml manifest

I want a variable on Ansible to be active or passive depending on the condition. I am using the role "davidwittman.redis". I'm setting up a redis cluster. I need to run a single yml file by ...
spala's user avatar
  • 85
0 votes
1 answer
1k views

ansible roles split tasks/main.yml in multiple files

I want to split my tasks/main.yml into different files in my Ansible role. With defaults/ and vars/, Ansible supports the creation of a main directory instead of the main.yml, from which all *.yml ...
FDo's user avatar
  • 17
0 votes
1 answer
88 views

Ansible Role Structuring

I'm new to Ansible and currently building out a few plays to perform common tasks such as performing pre & post installs for our software in dev/test. A scenario I’m working on is configuring a ...
BradSherwin's user avatar
0 votes
1 answer
603 views

Ansible collection with role-scope custom modules

I am trying to convert my pile of Ansible playbooks, roles, tasks, etc into a formalized Ansible Collection to better support re-use and modularity. The TL;DR is that I am having issues packaging a ...
enpaul's user avatar
  • 266
0 votes
1 answer
1k views

ModuleNotFoundError: No module named 'kubernetes'

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'kubernetes' failed: [ubuntu] (item={'name': 'deploymentnginx.yaml....
Srinivas Reddy's user avatar
1 vote
2 answers
300 views

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: ...
Cherie's user avatar
  • 31
0 votes
1 answer
950 views

ansible docker-compose module, different result from ansible than over ssh on the host

I have a task in my Ansible Bitbucket role that simply starts two docker-compose.yml files. When executing this from Ansible it fails but when I execute the same command over ssh on the actual server ...
Oskar Granlund's user avatar
3 votes
1 answer
454 views

Ansible - generate docs from role argument spec

Is there any way to generate a markdown documentation from ansible role argument spec? https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#role-argument-validation I could ...
ProfHase85's user avatar
  • 11.8k
0 votes
1 answer
1k views

delegate_to on individual host not working under ansible role

I have following code in ansible. elasticsearch role is set up to run as below on elasticsearch host group which consists of 3 es nodes. - name: elasticsearch hosts: elasticsearch become: true ...
prat's user avatar
  • 103
0 votes
1 answer
684 views

ansible play to execute same role against 2 host groups with different parameters passed to each host group

My use case is to use a single playbook to run the same role on 2 different host groups, but I want to pass different variable values depending on the host group the role is executing against. I've ...
joey_82's user avatar
  • 41
1 vote
2 answers
2k views

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 ...
jessefournier's user avatar
-2 votes
1 answer
124 views

Ansible: precedence for changes to the same file from three different roles

So, I was reading https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#using-allow-duplicates-true trying to figure out what's going wrong with my playbook. This playbook ...
rofz's user avatar
  • 91
1 vote
1 answer
379 views

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 ...
ActualChipmunk's user avatar
1 vote
1 answer
873 views

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 ...
Ashar's user avatar
  • 3,037
2 votes
2 answers
3k views

How to include roles in another role

I have organized all my playbooks into roles. Now that I have all the roles, I'm trying to create a new role that would include all the other roles. In Ansible, is it possible to create a role that ...
jessefournier's user avatar
1 vote
1 answer
4k views

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 /home/...
tribbloid's user avatar
  • 3,756
1 vote
2 answers
218 views

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" ...
Andre's user avatar
  • 39
0 votes
0 answers
202 views

Changing host in a role

I was assigned to create playbook that will be used by all teams within our department. Under this circumstances it has to be flexible. It should allow to choose technologies (depending on project/...
Mateo's user avatar
  • 1

1
2 3 4 5