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

这解决了我的任务