skip to Main Content

I want to download data from git only on first run of playbook.
For example, I have this

- name: Check if Magento is already installed
  stat: path=/var/www/html/index.php
  register: index_php
- name: Deploy the latest version from OpenMage github, only if it is not already installed
  git:
    repo: 'https://github.com/OpenMage/magento-mirror'
    dest: /var/www/html
    run_once: true 
  when: not index_php.stat.exists

Because of some another commands I would run again the same playbook, but without few commands like git.

I tried with register index.php, but afterwards if there is a difference between local and remote repository, I’m getting “msg”: “Local modifications exist in repository (force=no).”

Just to mention, I’m very new with Ansible.

2

Answers


  1. Concept of run_once is to only run a task one time for a batch of hosts. This is not what you want, I think.

    An option would be to use a lock file. For example:

    - name: Check Magento lock
      stat:
        path: /var/lock/ansible-magento.lock
      register: lock
    
    - name: Deploy the latest version from OpenMage github
      block:
        - git:
            repo: 'https://github.com/OpenMage/magento-mirror'
            dest: /var/www/html
        - file:
            path: /var/lock/ansible-magento.lock
            state: touch
      when: not lock.stat.exists
    

    (not tested)

    Login or Signup to reply.
  2. Maybe the “update” option in the git ansible module be worth for you:

    Check the doc page.

    update: no
    

    This is the explanation there:

    If no, do not retrieve new revisions from the origin repository
    Operations like archive will work on the existing (old) repository and
    might not respond to changes to the options version or remote.

    The default is “yes”.

    Also, check the example in the same doc page:

    # Example just ensuring the repo checkout exists
    - git:
        repo: 'https://foosball.example.org/path/to/repo.git'
        dest: /srv/checkout
        update: no
    

    I hope it can help you!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search