我只想在首次运行Playbook时从git下载数据。 例如,我有这个
- 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
由于其他一些命令,我将再次运行同一本剧本,但没有git之类的命令。
我尝试使用寄存器index.php,但是此后,如果本地存储库和远程存储库之间存在差异,我会得到“ msg”:“存储库中存在本地修改(force = no)。”
只需提一下,我对Ansible还是很陌生。
答案 0 :(得分:2)
也许git ansible模块中的“更新”选项对您有价值:
检查doc page。
update: no
这是那里的解释:
如果 否 ,请勿从原始存储库中检索新修订 存档等操作将在现有(旧)存储库上运行,并且 可能不会响应对选项版本或远程选项的更改。
默认值为“是”。
此外,请在同一文档页面中查看示例:
# Example just ensuring the repo checkout exists
- git:
repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout
update: no
希望它能对您有所帮助!
答案 1 :(得分:0)
run_once 的概念是to only run a task one time for a batch of hosts。我想这不是您想要的。
一种选择是使用lock file。例如:
- 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
(未经测试)