【问题标题】:Ansible Task Clone Private Repo HangsAnsible 任务克隆私有仓库挂起
【发布时间】:2017-05-14 06:59:57
【问题描述】:

设置一个 repo 来设置一个 Laravel 服务器。基本上使用 Ansible 的配置脚本。repo 称为Stedding。它基于Digital Ocean tutorial 和Roots Trellis 的一些代码,因为我需要PHP 7.1 包。

现在的问题是私有 Github 存储库没有被克隆。一直在阅读 ssh 代理、转发和所有这些。尝试了 sudoers 和 ansible.cfg 设置,例如 here。但还没有成功。我不喜欢添加私钥。 所以我尝试了 Geerlingguy 建议的 here 使用

Host [server-address-here] [ip-address-here]
    ForwardAgent yes

在~./ssh/config 内。我还补充说:

[ssh_connection]
ssh_args=-o ForwardAgent=yes

到 ansible.cfg。这是为了正确转发并避免添加私有 ssh 密钥。但是由于 /var/www/ 是 0700 www-data:www-data 我无法关闭 become 以成为 sudo 并完成它,因为这样就没有足够的权限:

"msg": "Could not open /var/www, [Errno 13] Permission denied: '/var/www'", 
    "rc": 13

他提到的这个是转发工作所必需的。

主要代码sn -p加载克隆任务是:

- name: create /var/www/ directory
    file: dest=/var/www/ state=directory owner=www-data group=www-data mode=0700

  - name: Clone git repository
    git:
      repo: "{{ repo_url }}"
      dest: /var/www/laravel
      version: master
      update: no
      accept_hostkey: yes
    become: yes
    become_user: www-data
    register: cloned

在当前设置下,一切都挂在:

TASK [Clone git repository] ****************************************************
task path: /Users/jasper/webdesign/stedding/php.yml:39
Using module file /usr/local/Cellar/ansible/2.2.1.0_2/libexec/lib/python2.7/site-packages/ansible/modules/core/source_control/git.py
<xxx.xxx.xx.xxx> ESTABLISH SSH CONNECTION FOR USER: laravel
<xxx.xxx.xx.xxx> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=laravel -o ConnectTimeout=10 -o ControlPath=/Users/jasper/.ansible/cp/ansible-ssh-%h-%p-%r 128.199.35.232 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1494744537.18-20302566024245 `" && echo ansible-tmp-1494744537.18-20302566024245="` echo /tmp/ansible-tmp-1494744537.18-20302566024245 `" ) && sleep 0'"'"''
<xxx.xxx.xx.xxx> PUT /var/folders/_4/g8fn6chn46g9v058h8k4pzpw0000gn/T/tmpO09os2 TO /tmp/ansible-tmp-1494744537.18-20302566024245/git.py
<xxx.xxx.xx.xxx> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=laravel -o ConnectTimeout=10 -o ControlPath=/Users/jasper/.ansible/cp/ansible-ssh-%h-%p-%r '[xxx.xxx.xx.xxx]'
<xxx.xxx.xx.xxx> ESTABLISH SSH CONNECTION FOR USER: laravel
<xxx.xxx.xx.xxx> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=laravel -o ConnectTimeout=10 -o ControlPath=/Users/jasper/.ansible/cp/ansible-ssh-%h-%p-%r xxx.xxx.xx.xxx '/bin/sh -c '"'"'setfacl -m u:www-data:r-x /tmp/ansible-tmp-1494744537.18-20302566024245/ /tmp/ansible-tmp-1494744537.18-20302566024245/git.py && sleep 0'"'"''
<xxx.xxx.xx.xxx> ESTABLISH SSH CONNECTION FOR USER: laravel
<xxx.xxx.xx.xxx> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=laravel -o ConnectTimeout=10 -o ControlPath=/Users/jasper/.ansible/cp/ansible-ssh-%h-%p-%r -tt xxx.xxx.xx.xxx '/bin/sh -c '"'"'sudo -H -S  -p "[sudo via ansible, key=vvqwwyduilnxfbnxgpojunlavpkasofr] password: " -u www-data /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-vvqwwyduilnxfbnxgpojunlavpkasofr; /usr/bin/python /tmp/ansible-tmp-1494744537.18-20302566024245/git.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''

这也发生在我使用 (Ansible suggestion) 将服务器上的 Github 添加到已知主机后:

ssh-keyscan -H github.com > /etc/ssh/ssh_known_hosts

知道如何进行克隆工作并确保目录权限和权限安全以安装 Laravel 应用程序吗?

【问题讨论】:

  • 将 repo 克隆为 laravel 用户(因为只有此用户可以访问您代理的密钥),然后使用 file 模块获得正确的所有权。在 Ansible 中,成为非特权用户是一件棘手的事情。
  • 是的,我想通了。还意识到我毕竟没有在~./ssh/config 中正确设置AgentForwarding。还不能回答我自己的问题。但是已经更新了一些 repo 并且克隆现在正在工作。很幸运地找到了一个帮助我正确调试和克隆的要点:gist.github.com/pogorelov-ss/41893e17c7c4776d4d57。由于远程上的 git 路径已关闭,尚未全部完成,但我通过了冻结阶段并克隆了它。

标签: laravel github ansible


【解决方案1】:

最后主要问题是我需要正确设置代理转发。我是用

Host *
  ForwardAgent yes

在~/.ssh/config 那和我决定使用 root 作为用户来设置大多数剧本材料。 Root 不需要切换到 sudo。对于像克隆这样的部分,我可以使用用户 laravel,因为它可以作为所有者访问 webroot,并且效果也很好。所以那里也不需要 sudo 。

在 Ansible 创建 sudo 用户后,我还没有解决切换到 sudo 的问题。对这一切还是陌生的。但取得了进展。而且我相信主机转发提示会帮助很多人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多