I need to run some roles in concurrent mode in Ansible.
I run ansible via:
ansible-playbook install_full.yml --tags "10_clean_up,20_pull_images,30_install_postgres_11,40_install_jboss-eap-7.0" --extra-vars "ansible_user=user ansible_password=password"
The playbook install_full.yml looks like:
- hosts: localhost
vars_files:
- "vars/build.yml"
roles:
- { role: 10_clean_up, tags: 10_clean_up }
- { role: 20_pull_images, tags: 20_pull_images }
- { role: 30_install_postgres_11, tags: 30_install_postgres_11 }
- { role: 40_install_jboss-eap-7.0, tags: 40_install_jboss-eap-7.0 }
30 and 40 role can be run in the same time (to save some time), is it possible to run couple of roles in parallel, not like now - by order list ?
Thanks on advance!
It is not possible at this time and many have asked for that feature. From the ansible project : https://github.com/ansible/ansible/issues/19083.
FYI it is possible to use async on tasks, but it is not possible to use it on roles.
You'd need strategy: free for the set of roles you want to run at the same time. Check this out:
https://medium.com/#ibrahimgunduz34/parallel-playbook-execution-in-ansible-30799ccda4e0
Related
I have a playbook than lauches multiple rĂ´les, one of them manage the install and the uninstall of sophos antivirus. It can handle the installation or the unistallation using tags but musn't obviously do booth a the same time.
So my question is how can I lanch just this role in the playbook with the tag install without overloading all the tasks inside this role? I just want to execute only the taggued task, as the intended use for the tasks in general.
I've tried a few syntax but none seems to work, it always overload all the tasks with the tag instead of executing the taggued tasks:
roles:
- role: ../roles/repos.linux
- role: ../roles/sophos
tags: [install,check]
or roles:
- role: ../roles/repos.linux
- {role: ../roles/sophos, tags: install,check}
Expected:
The role execute only the taggued tasks called
Actual:
Every task is overloaded with the tags I try to execute
Use include_role. For example:
tasks:
- include_role:
name: repos.linux
apply:
tags:
- install
- check
As per ansible documentation here I am using the below syntax to trigger a role when the variable "mdb_user" starts with prod.
- hosts: category_workstation
gather_facts: False
name: common workstation applications
roles:
- apps_workstation
- { role: apps_workstation_production, when: mdb_user.startswith('prod') }
This works nicely but what i want to know is if i can do something similar to adjust the variables fed to the role in different conditions. For instance the below:
- hosts : category_workstation
name: common workstation applications
roles:
- apps_workstation
- { role: apps_workstation_production, vars={'user':'prod'}, when: mdb_user.startswith('prod')}
Currently I am having to use when and set_fact to get the right variables setup before caling a roles and this approach above (if possible) seems more concise.
You can try something like:
- hosts : category_workstation
name: common workstation applications
roles:
- apps_workstation
- { role: apps_workstation_production, user: prod, when: mdb_user.startswith('prod')}
I'm using Ansible to do the automation of my systems.
I have an Ansible playbook that depends on two roles.
The first role creates a user ("specific_user") on a remote server.
The second role uses this user to do a bunch of stuff.
My first solution was the following (my playbook) :
---
- hosts: all
roles:
- { role: ansible-role1, remote_user: root }
- { role: ansible-role2, remote_user: specific_user }
...
However, I'm getting the following warning from Ansible when running it:
Using 'remote_user' as a role param has been deprecated.
In the future, these values should be entered in the `vars:` section for
roles, but for now we'll store it as both a param and an attribute..
What is the alternative ?
Currently this is only a warning message (until version 2.7 of Ansible).
As the message suggests, you need to change syntax to (using YAML in the example below, because it's more readable):
roles:
- role: ansible-role1
vars:
remote_user: root
- role: ansible-role2
vars:
remote_user: specific_user
...
I'm searching for a way to always run a role, regardless of --tags args.
Here is a simple playbook:
- hosts: all
roles:
- { role: role1, tags: always },
- { role: role2, tags: tag1 },
- { role: role3, tags: tag2 }
I would like only role1 and role2 to run when I launch the following filter (instead of only role2):
ansible-playbook -i hosts deploy.yml --tags tag1
I though it was the default behavior with the special always tag (see http://docs.ansible.com/ansible/playbooks_tags.html#special-tags)
I'm playing with Ansible 1.8.4.
Most probably your Ansible version is the problem.
The always tag was introduced with this pull request, which was merged into the devel branch on February 25. According to the releases, the next released version after that date was Ansible 1.9.0-1.
I have a very simple ansible configuration:
- name: Prepare and intsall RethinkDB on available machines
hosts: all
roles:
- { role: rethinkdb, tags: ["install"] }
And a corresponding vagrant config:
universe.vm.provision "ansible" do |a|
a.playbook = "configuration.yml"
a.groups = {
"primary" => ["rmaster"],
"secondary" => ["rsecondary"]
}
end
The problem is if i call vagrant provision ansible runs rethinkdb role ignoring specified in configuration.yml file install tag. Though it works if i put it into vagrant as a.tags = "install", but it won't work if i have a sequence of ansible tasks to run with different tags, so i'd like to specify them from ansible playbook.
As far as I know, it's not possible for a playbook to define the role tags that will be run by the role. What tags: ["install"] does is to assign the install tag to the tasks from the rethinkdb role ("you may wish to assign tags to the roles you specify").
If your install, configure, launch, etc. tags are run in sequence, then you should be able to dispatch them to different (possibly dependent) roles. If not, then your only other solution is to run individual tasks using not tags but variable values.
E.g:
in roles/rethinkdb/tasks/main.yml:
- name: my_task
when: run_rethinkdb_install
in playbook.yml:
- name: Prepare and intsall RethinkDB on available machines
hosts: all
vars:
run_rethinkdb_install: True
roles:
- { role: rethinkdb, tags: ["install"] }