M
M
Mika Slepinin2016-11-22 18:33:42
Ansible
Mika Slepinin, 2016-11-22 18:33:42

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

I start now like this:
ansible-playbook -i hosts site.yml
And I just put the "#" symbol in front of those roles that do not need to be performed now. But I think there is another way.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
mureevms, 2016-11-22
@mureevms

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 command
ansible-playbook -i hosts role1/tasks/main.yml

S
Sanes, 2016-11-22
@Sanes

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?

M
Mika Slepinin, 2016-11-23
@mikalaikaia

Solved this question like this:
site.yml looks like this:

---
- hosts:  demo
  remote_user: jenkins
  become: yes

  roles:
  - '{{ ROLE }}'

I run it like this:
In order to run on another and on different groups of hosts, you need to bring site.yml to this form:
---
- hosts:  '{{ TARGETIP }}'
  remote_user: jenkins
  become: yes

  roles:
  - '{{ ROLE }}'

Run like this:
ansible-playbook -i hosts site.yml -e "ROLE=role1" -e "TARGETIP=demo"

A
alexander, 2016-11-23
@beza2000

Use tags.
Like this:
...
roles:
- { role: role1, tags: role1}
- { role: role2, tags: role2}
- { role: role3, tags: role3}
...
Execute
ansible-playbook -i hosts site. yml -t role1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question