0

My playbook has the snippet below. It correctly installs the software, but when I rerun the playbook, the "configure" and "make install" steps are run again. The play recap shows 2 changes. The state of the computer is correct upon completion of script, but I would rather not re-run these steps. How can I skip running the steps that have already been run?

- name: Install smalt
  block:
    # Download and uncompress smalt
    - unarchive:
        src="https://sourceforge.net/projects/smalt/files/smalt-0.7.6-static.tar.gz"
        dest="{{ansible_user_dir}}/software"
        creates="{{ansible_user_dir}}/software/smalt-0.7.6"
        copy=no
    - name: configure
      command: ./configure
      args:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
    - make:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
    - make:
        chdir: "{{ansible_user_dir}}/software/smalt-0.7.6"
        target: install
      become: yes
Steve
  • 1,250
  • 11
  • 25
  • 2
    you could try using the `creates` parameter with configure by checking if the Makefile is already created, for the second one -probably woudn't work- remove the second make, just make install. alternatively you could make it a role for installing smalt, and check if it is [installed](http://stackoverflow.com/questions/35654286/ddg#35680071) before calling the role or [including](https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#applying-when-to-roles-imports-and-includes) it. – hchandad Aug 17 '18 at 16:03
  • @fins Does `make` module support `creates` parameter? – techraf Aug 17 '18 at 17:21
  • no i don't think it does, one can pass args to make, if that could help. – hchandad Aug 17 '18 at 20:51

1 Answers1

1

How can I skip running the steps that have already been run?

By testing the actual desired state before evaluating that block, and then guarding the block with a when clause; for example:

- name: check for smalt installation
  stat:
    path: /usr/local/bin/smalt  # <-- or whatever
  register: smalt_bin

- name: Install smalt
  when: not smalt_bin.stat.exists
  block:
    - unarchive: # etc etc
mdaniel
  • 31,240
  • 5
  • 55
  • 58