Answer the question
In order to leave comments, you need to log in
How to run only one Ansible role?
Good evening!
There is a project for Ansible which contains several roles. How to run a playbook so that only one role is executed, but understands the variables?
site.yml looks like this:
---
- hosts: demo
remote_user: jenkins
become: yes
become_method: sudo
roles:
- role1
- role3
- role4
- role5
- role6
- role7
ansible-playbook -i hosts site.yml
Answer the question
In order to leave comments, you need to log in
If people before you did everything right, then in the role1 directory (let’s say it needs to be executed) there should be a tasks directory, and in it the main.yml file, so you need to pass it as an argument to the commandansible-playbook -i hosts role1/tasks/main.yml
Maybe a little off topic. Interested in Ansible .
What is the meaning of roles? I have a strategy to solve the problem with one playbook. (circulation problem).
On Git, take a look at my train of thought. Messed up the project , maybe not?
Solved this question like this:
site.yml looks like this:
---
- hosts: demo
remote_user: jenkins
become: yes
roles:
- '{{ ROLE }}'
---
- hosts: '{{ TARGETIP }}'
remote_user: jenkins
become: yes
roles:
- '{{ ROLE }}'
ansible-playbook -i hosts site.yml -e "ROLE=role1" -e "TARGETIP=demo"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question