Ansible复制模块需要可写的父目录吗? [英] Ansible copy module requires writable parent directory?
问题描述
需要将/proc/sys/net/ipv4/conf/all/forwarding设置为1
Need to set /proc/sys/net/ipv4/conf/all/forwarding to 1
可以通过命令
- 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不可写"
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屋!