Ansible 任务克隆私有仓库挂起

兰德

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

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

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

里面~./ssh/config我还补充道:

[ssh_connection]
ssh_args=-o ForwardAgent=yes

ansible.cfg。这是为了正确转发并避免添加私有 ssh 密钥。但正如/var/www/是0700www-data:www-data我不能关闭become,成为sudo和完成它,因为那么将没有足够的权限:

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

他提到的这一点是进行转发工作所必需的。

加载克隆任务的主要代码片段是:

- 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 建议将服务器上的 Github 添加到已知主机之后,也会发生这种情况

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

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

兰德

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

Host *
  ForwardAgent yes

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我的Ansible任务挂起?

来自分类Dev

启动 mongod 服务的 Ansible 任务永远挂起

来自分类Dev

将github仓库克隆为私有gitlab仓库

来自分类Dev

在Ansible中杀死任务

来自分类Dev

Ansible:角色的任务结构

来自分类Dev

Ansible任务是否运行?

来自分类Dev

从git仓库使用ansible模块?

来自分类Dev

如何使用Ansible git模块克隆一个空的裸仓库?

来自分类Dev

如何使用Ansible git模块克隆一个空的裸仓库?

来自分类Dev

Ansible:对任务失败执行清理

来自分类Dev

失败时呼叫Ansible任务

来自分类Dev

Ansible任务中的MySQL错误

来自分类Dev

基于调试输出的 Ansible 任务

来自分类Dev

Ansible:ufw不是ansible任务或处理程序中的合法参数

来自分类Dev

任务名称中的Ansible Useventory_hostname或ansible_hostname

来自分类Dev

如何将ansible剧本的所有任务限制为ansible_os_family?

来自分类Dev

如何将ansible剧本的所有任务限制为ansible_os_family?

来自分类Dev

ansible shell任务错误输出而没有正确的消息

来自分类Dev

ansible:我没有收到任务的完整错误消息

来自分类Dev

如何使Ansible仅打印具有标准输出的任务

来自分类Dev

具有动态变量的Ansible循环任务

来自分类Dev

任务中带有变量的ansible调用处理程序

来自分类Dev

Ansible:任务或模板中有条件吗?

来自分类Dev

Ansible 任务失败,即使有 ignore_errors

来自分类Dev

Ansible在解析广告资源后挂起

来自分类Dev

通过ansible剧本从git克隆特定分支

来自分类Dev

无法使用ansible克隆git repo

来自分类Dev

Ansible:没有匹配的主机

来自分类Dev

Ansible:没有密码的sudo