我希望使用file.append状态更新文件,更新的内容是定义的jinja模版,里面我会传入一些变量,平时直接定义default并写变量对应的kv就可以了,但是这个状态模块不行
1 [root@linux-node1 append]# cat append.sls 2 /root/file: 3 file.append: 4 - template: jinja 5 - source: salt://append/templates/keep.tmpl 6 #- context: 7 # port: 1 8 - default: 9 port: 1
此时报port未被定义,并出现一个警告让我去配置context
1 Warnings: 'default' and 'port' are invalid keyword arguments for 2 'file.append'. If you were trying to pass additional data to be 3 used in a template context, please populate 'context' with 'key: 4 value' pairs. Your approach will work until Salt Oxygen is out. 5 Please update your state files.
1 [root@linux-node1 append]# cat append.sls 2 /root/file: 3 file.append: 4 - template: jinja 5 - source: salt://append/templates/keep.tmpl 6 - context: 7 - port: 1
这时候报请求参数长度错误....我也是醉了
1 ValueError: dictionary update sequence element #0 has length 1; 2 is required
或者直接给一个通过jinja模版增加文件内容的例子也可以
我是在stackoverflow里有人给了个链接页面看到了这个的写法https://docs.saltstack.com/en/latest/topics/troubleshooting/yaml_idiosyncrasies.html#nested-dictionaries
/root/file: file.append: - template: jinja - source: salt://append/templates/keep.tmpl - context: {'port': '1'}