Ansible 2.1.0 使用 become/become_user 无法设置临时文件的权限 [英] Ansible 2.1.0 using become/become_user fails to set permissions on temp file

查看:29
本文介绍了Ansible 2.1.0 使用 become/become_user 无法设置临时文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上有一个 ansible 2.1.0,我在那里通过 vagrant 和 PC 进行部署.部署"角色有:

I have an ansible 2.1.0 on my server, where I do deployment via vagrant and on PC too. The role "deploy" have :

- name: upload code
  become: true
  become_user: www-data
  git: repo=git@bitbucket.org:****.git
     dest=/var/www/main
     key_file=/var/www/.ssh/id_rsa
     accept_hostkey=true
     update=yes
     force=yes
 register: fresh_code
 notify: restart php-fpm
 tags: fresh_code

在使用 ansible 2.1.0 的情况下,我收到一个错误:

In this case with ansible 2.1.0 I get an error:

fatal: [default]: FAILED! => {"failed": true, "msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user. For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"}

我在我的电脑上使用的 ansible 2.0.1.0,通常都是 - 文件夹/var/www/有文件夹 main 与所有者和组 www-data

It it ansible 2.0.1.0 which I use on my PC, is all normally - folder /var/www/ have folder main with owner and group www-data

如果我只使用 become_user: www-data 并且如果我使用 become_method: sudo with become_user: www-data - 我有同样的错误

If I use only became_user: www-data and if I use become_method: sudo with became_user: www-data - i got same error

需要怎么做才能解决这个问题?

What need to do to resolve this?

推荐答案

问题在于 www-data 无法访问您创建的默认非 root ansible 用户创建的用于连接到机器.此外,错误消息清楚地指向 ansible 的文档,其中描述了您必须选择的选项从 ansible 2.0 或更低版本升级时修复此问题.

The problem is that www-data cannot access the same files your default non-root ansible user created you use to connect to the machine. Also the error message clearly points to ansible's documentation which describes what options you have to fix this issue when upgrading from ansible 2.0 or below.

他们提出了三种正确解决问题的方法:

They suggest three ways to properly fix the issue:

  • 使用流水线.启用流水线后,Ansible 不会将模块保存到客户端上的临时文件中.相反,它将模块通过管道传输到远程 python 解释器的标准输入.流水线不适用于非 Python 模块.
  • 在托管主机上安装文件系统 acl 支持.如果远程主机上的临时目录在启用文件系统 acls 的情况下挂载并且 setfacl 工具位于远程 PATH 中,那么 Ansible 将使用文件系统 acls 与第二个非特权共享模块文件,而不必让每个人都可以读取该文件.
  • 不要通过成为非特权用户在远程机器上执行操作.当您成为 root 用户或不使用 become 时,临时文件受 UNIX 文件权限保护.在 Ansible 2.1 及更高版本中,如果您以 root 用户身份连接到受管计算机,然后将其用于非特权帐户,则 UNIX 文件权限也是安全的.

或者,如果您无法进行任何这些修复,那么您可以强制 ansible 以更不安全的方式运行(这似乎是 ansible 2 及以下版本中的默认设置),这也应该可以解决您的问题,但不会修复潜在的安全风险:

Or if you cannot do any of these fixes, then you can force ansible to run in a bit more insecure way (which seemed to be the default in ansible 2 and below), which should also fix your problem, but would not fix the underlying security risk:

如果您无法进行上述任何更改来解决问题,并且您确定您正在运行的机器足够安全,您想要在那里运行的模块是世界可读的,您可以打开 ansible.cfg 文件中的 >allow_world_readable_tmpfiles.设置 allow_world_readable_tmpfiles 会将其从错误更改为警告,并允许任务像 2.1 之前一样运行.

If you can’t make any of the changes above to resolve the problem and you decide that the machine you’re running on is secure enough for the modules you want to run there to be world readable you can turn on allow_world_readable_tmpfiles in the ansible.cfg file. Setting allow_world_readable_tmpfiles will change this from an error into a warning and allow the task to run as it did prior to 2.1.

这篇关于Ansible 2.1.0 使用 become/become_user 无法设置临时文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆