设置一个 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] 删除。
我来说两句