indempotence best practices questions and playbook example

I’m a little confused about best practices for indempotence in Ansible. Here’s a quick playbook that does the following:

  • installs mysql-server on a minimal debian system, preseeding the questions (ugh) the package asks to set the mysql password
  • installs zoneminder
  • conditionally copies in a gzipped dumpfile of a pre-configured zoneminder setup, unzips it, restores it
  • and links the zoneminder stuff into the apache2 web configuration

Where I’m confused is the convoluted gymnastics needed to do things conditionally, only if there was something done above. The playbook below works fine, but it sure seems like a lot of work to do to make each step indempotent. Am I missing something in best practices or syntax ?

Note - yes I set a db password to ‘root’ in this example, and I’m keying off stuff stashed in /tmp existing or not. Don’t sweat that part, it’s just an example. I’m interested in better understanding best practices re: how to do the playbook structure and logic/flow. Thanks.


unfortunately, this one always comes up as changed

  • name: mysql | set debconf values
    debconf: name=‘mysql-server-5.5’ question={{ item.question}} value={{ item.value }} vtype={{ item.vtype }}
    with_items:

  • { question: ‘mysql-server/root_password’, value: ‘root’, vtype: ‘password’ }

  • { question: ‘mysql-server/root_password_again’, value: ‘root’, vtype: ‘password’ }

  • name: Install Mysql

apt: package={{ item }} state=present
with_items:

  • mysql-server