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

Is it possible to ignore missing role in Ansible?

I'm using Vagrant+Ansible on a project. I want to make it optional for the user to provide a role called "workspace" which will be included in the provisioning. This allows the user to set his own preferred prompt, editor etc. If a role that doesn't…
Hubro
  • 56,214
  • 69
  • 228
  • 381
3
votes
2 answers

Ansible Roles Global Variables

I use roles to deploy my machines, Roles have vars, but sometimes i have multiple role and i want to put a global variable file in the root folders, so ansible use vars/global.yml and overwrite role/vars/main.yml #vars/global.yml somevariable:…
Rahul Sharma
  • 779
  • 2
  • 12
  • 27
3
votes
1 answer

How do you use become when invoking a role in ansible?

How do you become a user when using a role in ansible? For example, how would I install nodejs as root using the geerlingguy.nodejs role from ansible galaxy? Here is the relevant portion of what I have: roles: - geerlingguy.nodejs become:…
John Cummings
  • 1,949
  • 3
  • 22
  • 38
2
votes
1 answer

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 module/filter during runtime. molecule 4.0.4 using…
TRW
  • 876
  • 7
  • 23
2
votes
1 answer

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/update.yml: - name: role 2 import_role: …
user592748
  • 1,194
  • 3
  • 21
  • 45
2
votes
1 answer

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: update_cache: true upgrade: dist - name:…
Floren
  • 113
  • 11
2
votes
1 answer

'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. - name: Check http status(yes or no) shell: | …
raptor85
  • 125
  • 2
  • 4
  • 12
2
votes
1 answer

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 hardcoded in the module code itself. How can I…
2
votes
1 answer

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 not find anything in ansible-doc, the format itself…
ProfHase85
  • 11,763
  • 7
  • 48
  • 66
2
votes
2 answers

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 just calls other roles? If so, is it possible to do…
jessefournier
  • 181
  • 1
  • 2
  • 13
2
votes
1 answer

In ansible, is there a way to register the result of a role?

I'm essentially trying to only run a particular role if the other role was able to run without error. Is this possible? I've tried something like this but it is not working as expected tasks: - include_role: name: user_role register: users -…
bobcat
  • 165
  • 1
  • 11
2
votes
1 answer

is it possible to run a shell script from ansible role/file directory?

I have a role that needs to run a shell script test.sh saved under files directory of the role and my task looks like as follows I am getting the following error name: Execute shell script command: sh test.sh FAILED! => {"changed": true,…
Mikias Hundie
  • 107
  • 1
  • 2
  • 11
2
votes
0 answers

Best way to update the same file from multiple ansible roles

I'm trying to write my first ansible playbook to setup my Arch Linux workstations and servers. So far everything worked fine but now I've run into a problem I can't really wrap my head around. I'm trying to have multiple roles that require changes…
Marc
  • 41
  • 2
2
votes
1 answer

Conditional role inclusion fails in Ansible

I want to run an Ansible role conditionally, i.e. only when some binary does NOT exist (which for me implies absence of some particular app installation). Something like the pattern used here. Using the following code in my playbook: - hosts:…
pkaramol
  • 16,451
  • 43
  • 149
  • 324
2
votes
1 answer

In an Ansible playbook, how do I apply group-based roles with more parallelism?

I'm using Ansible 2.1. Let's say my hosts are already grouped in inventory. Then I run a playbook like this: - hosts: foo roles: - bar - hosts: baz roles: - eek ...more... Ansible seems to apply the roles one by one, no matter how…
chris
  • 41
  • 4