Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何仅在第一次运行playbook时运行命令,在下次重新运行时跳过?_Git_Ansible - Fatal编程技术网

Git 如何仅在第一次运行playbook时运行命令,在下次重新运行时跳过?

Git 如何仅在第一次运行playbook时运行命令,在下次重新运行时跳过?,git,ansible,Git,Ansible,我只想在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:

我只想在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这样的命令

我尝试使用register index.php,但之后如果本地存储库和远程存储库之间存在差异,我会得到“msg”:“存储库中存在本地修改(force=no)。”

我对Ansible非常陌生。

run\u once的概念是。我想这不是你想要的

一个选择是使用一个。例如:

- 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
(未测试)

也许git ansible模块中的“更新”选项值得您:

检查一下

这里的解释是:

如果,则不要从原始存储库检索新修订 归档等操作将在现有(旧)存储库和 可能不会响应对选项版本或远程的更改

默认值为“是”

此外,请检查同一文档页面中的示例:

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

我希望它能帮助你

您好,谢谢,这个例子非常适合我提到的这个问题。但我选择了来自弗拉基米尔·博特卡的最佳答案,因为这是我问题的一般答案。谢谢:)
# Example just ensuring the repo checkout exists
- git:
    repo: 'https://foosball.example.org/path/to/repo.git'
    dest: /srv/checkout
    update: no