首页 新闻 会员 周边

salt file.append context是在理解不了

0
悬赏园豆:5 [已关闭问题] 关闭于 2017-11-30 13:52

我希望使用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模版增加文件内容的例子也可以

北方姆Q的主页 北方姆Q | 小虾三级 | 园豆:1118
提问于:2017-11-30 12:10
< >
分享
所有回答(1)
0

我是在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'}
北方姆Q | 园豆:1118 (小虾三级) | 2017-11-30 13:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册