6

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?

techraf
  • 64,883
  • 27
  • 193
  • 198

1 Answers1

9

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).

user2599522
  • 3,005
  • 2
  • 23
  • 40
  • Just very concrete. We are generating certificates for the server. I have no clue why, but when it finds file (old certificate), Ansible goes over. But I need to create new one and overwrite the old one. Do you suggest to create e.g. SHA over the certificate and compare it? – Seweryn Habdank-Wojewódzki Nov 30 '16 at 10:03
  • 1
    I've updated my answer with my approach to the matter – user2599522 Nov 30 '16 at 10:21