Ansible 复制模块需要可写的父目录? [英] Ansible copy module requires writable parent directory?

查看:26
本文介绍了Ansible 复制模块需要可写的父目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要设置/proc/sys/net/ipv4/conf/all/forwarding为1

Need to set /proc/sys/net/ipv4/conf/all/forwarding to 1

这可以通过命令轻松完成

That's can be easily done via command

- name: Enable IPv4 traffic forwarding
  command: echo 1 > /proc/sys/net/ipv4/conf/all/forwarding

但这是不好的做法 - 它总是改变"的任务.

But that's bad practice - it will be always "changed" task.

所以我尝试了以下方法:

So I tried the following:

- name: Enable IPv4 traffic forwarding
  copy: content=1 dest="/proc/sys/net/ipv4/conf/all/forwarding" force=yes

失败并显示消息:目标/proc/sys/net/ipv4/conf/all not writable"

Which failed with msg: "Destination /proc/sys/net/ipv4/conf/all not writable"

根据来源看来像复制总是要求父目录是可写的.但是 1) 我不明白为什么 2) 任何其他惯用"方式将目标文件设置为所需值?

According to sources seems like copy always requires parent directory will be writable. But 1) I don't understand why 2) Any other "idiomatic" way to set destination file to required value?

推荐答案

虽然我还是不明白为什么复制需要检查父目录权限,感谢@larsks:

While I still do not understand why copy needs to check parent directory permissions, thanks to @larsks:

sysctl 模块 更改 sysctl.conf 和/proc 值

sysctl module changes both sysctl.conf and /proc values

这解决了我的任务

这篇关于Ansible 复制模块需要可写的父目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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