mrz*_*zrm 3 git ubuntu ansible devops
我正在尝试使用该模块通过Ansible克隆远程存储库git。这是任务配置:
- name: Clone repo
git:
repo: "{{ repository }}"
dest: "/home/{{ username }}/abc"
key_file: "{{ git_key_file }}"
register: code_update
Run Code Online (Sandbox Code Playgroud)
但不幸的是它失败并出现以下错误:
fatal: [xyz]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin '' /home/xyz/abc", "msg": "Cloning into '/home/xyz/abc'...\nfatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied\nfatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied\nfatal: unable to fork", "rc": 128, "stderr": "Cloning into '/home/xyz/abc'...\nfatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied\nfatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied\nfatal: unable to fork\n", "stderr_lines": ["Cloning into '/home/xyz/abc'...", "fatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied", "fatal: cannot exec '/tmp/tmpm9mfdkci': Permission denied", "fatal: unable to fork"], "stdout": "", "stdout_lines": []}
Run Code Online (Sandbox Code Playgroud)
值得一提的是,我可以直接在远程服务器上克隆存储库。我也尝试更改TMP和TMPDIR使用environment设置,但没有任何改变。
任何回应将不胜感激...
/tmp在服务器上安装了选项,noexec因此ansible无法执行其自己的临时脚本。推荐的修复方法是设置环境变量TMPDIR:
- name: Clone the git repo in a temporary directory
environment:
TMPDIR: "/home/{{ username }}/tmp"
git:
repo: "{{ repository }}"
dest: "/home/{{ username }}/abc"
key_file: "{{ git_key_file }}"
Run Code Online (Sandbox Code Playgroud)
确保目录存在。
参见https://github.com/ansible/ansible/issues/30064,尤其是。https://github.com/ansible/ansible/issues/30064#issuecomment-487149251