【发布时间】:2020-05-08 00:56:40
【问题描述】:
需要设置/proc/sys/net/ipv4/conf/all/forwarding为1
这可以通过命令轻松完成
- name: Enable IPv4 traffic forwarding
command: echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
但这是不好的做法 - 它总是会“改变”任务。
所以我尝试了以下方法:
- name: Enable IPv4 traffic forwarding
copy: content=1 dest="/proc/sys/net/ipv4/conf/all/forwarding" force=yes
失败并显示消息:“Destination /proc/sys/net/ipv4/conf/all not writable”
根据sources 似乎复制总是需要父目录是可写的。但是 1)我不明白为什么 2)任何其他“惯用”方式将目标文件设置为所需值?
【问题讨论】:
-
切换到“同步”模块能解决问题吗?
-
command: echo 1 > /proc/sys/net/ipv4/conf/all/forwarding会直接回显“1 > /proc/sys...”,而不是写入文件-command不会通过 shell 运行,因此 shell 元字符不会工作。你需要/想要shell: echo 1 > /proc/sys/net/ipv4/conf/all/forwarding。
标签: ansible