gpt4 book ai didi

安塞 bool : Git module clone of repository while re-run is throwing exception

转载 作者:行者123 更新时间:2023-12-02 18:44:13 25 4
gpt4 key购买 nike

我正在使用 ansible-playbook 来设置服务器,该服务器正在从 github 克隆存储库。当我重新运行剧本时,我收到异常 msg: fatal: 目标路径 '/webapps/........' 已经存在并且不是空目录。

TASK: [web | Setup the Git repo] **********************************************
failed: [192.168.1.96] => {"cmd": "/usr/bin/git clone --origin origin --branch master https://github.com/....../......git /webapps/....../...../....", "failed": true, "rc": 128}
stderr: fatal: destination path '/webapps/..../..../....' already exists and is not an empty directory.

msg: fatal: destination path '/webapps/..../..../....' already exists and is not an empty directory.

FATAL: all hosts have already failed -- aborting

剧本

- name: Setup the Git repo
git: repo={{ git_repo }}
version="{{ git_branch }}"
dest={{ project_path }}
accept_hostkey=yes
force=yes
when: setup_git_repo is defined and setup_git_repo
tags: git

- name: Delete all .pyc files
command: find . -name '*.pyc' -delete
args:
chdir: "{{ project_path }}"
tags: git

如果文件已克隆并存在于服务器中,如何跳过此步骤(或)覆盖文件。

最佳答案

我仍然遇到这个问题,并找到了以下(hacky)解决方法:

- name: Setup the Git repo
git: repo={{ git_repo }}
version="{{ git_branch }}"
dest={{ project_path }}
accept_hostkey=yes
force=yes
when: setup_git_repo is defined and setup_git_repo
tags: git
ignore_errors: yes
register: clone_command_res

- name: Only allow the expected failure
assert:
that: "not clone_command_res['failed'] or 'already exists and is not an empty directory' in clone_command_res['msg'].lower()"

在后面,错误消息可能会有所不同,具体取决于您之前的状态(例如我的错误消息是存储库中存在本地修改)或更糟糕的是,git和/或ansible版本。无论如何,只需包含预期的错误消息(有点像 try/catch)。

虽然如果 ansible git 模块中有针对这种情况的选项会更好,但现在应该可以了。

关于安塞 bool : Git module clone of repository while re-run is throwing exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34829765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com