Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible -> How to force execution of all tasks?

We would like to reset server installation.

We already have Ansible script to setup our server, so we want to execute it. However Ansible checks, that e.g. some files are existing and then skip steps where those files are prepared, but we would like to overwrite all.

Are there any convenient options to do that?

like image 939
Seweryn Habdank-Wojewódzki Avatar asked Nov 30 '16 09:11

Seweryn Habdank-Wojewódzki


People also ask

How you can run your all tasks at once in Ansible?

If you want to run multiple tasks in a playbook concurrently, use async with poll set to 0. When you set poll: 0 , Ansible starts the task and immediately moves on to the next task without waiting for a result. Each async task runs until it either completes, fails or times out (runs longer than its async value).

What is the default execution strategy in Ansible?

The default strategy Ansible uses, is called linear , and it works great a majority of the time, but what if you're automating a task that need to be done in a specific order or way. Strategies can be used to define how a playbook should be executed.

What is the Ansible playbook execution order?

Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.

What is Throttle Ansible?

Ansible completes the play on the specified number or percentage of hosts before starting the next batch of hosts. You can restrict the number of workers allotted to a block or task with throttle . You can control how Ansible selects the next host in a group to execute against with order .


1 Answers

updated based on comments

In that case (certs on server that need to be regenerated) i have a nuke flag in my playbook that is always set to false and a task that does the cleanup

- file:
    path: '{{ item }}'
    state: absent
  when: nuke
  with_items:
    - /path/to/file1
    - /path/to/file2

When i need to recreate stuff, i use ansible with

ansible-playbook pb.yml -e nuke=true

Its not the most elegant solution, but it gets the job done.


old obsolete answer

There isn't any standard way of doing this. But I dont think that there is any point in that.

Ansible guarantees that the final form of the thing (i.e. file) you are provisioning is matching what ever you told it to be.

For example, if you deploy a template like this

- template:
  src: ./foo
  dest: /etc/foo
  owner: root

and you execute it, the file is guaranteed to have the right contents and owned by user root.

There are lots of configs you can add to ensure that (checksums for get_url, etc).

like image 84
user2599522 Avatar answered Oct 02 '22 14:10

user2599522