目前正在使用 Ansible 将旧系统的配置移植到多个IBM
ISAM
9 个系统ISAM-Ansible-Roles
(https://github.com/IBM-Security/isam-ansible-roles)并且遇到特定字符串的问题。
我需要的结果是这样的:
request-log-format = { "seconds": "%{%s}t" }
我得到的.yml
文件如下:
---
- name: Run some commands
hosts: all
connection: local
vars:
username: "admin"
password: "password1234"
lmi_port: "443"
log_level: "CRITICAL"
force: True
start_config_wait_time: 120
roles:
- role: update_reverseproxy_conf
update_reverseproxy_conf_reverseproxy_id: "TestInstance"
update_reverseproxy_conf_entries:
- stanza_id: "logging"
entry_id: "request-log-format"
value_id: " { \"seconds\": \"%{%s}t\" } "
最后一行value_id:
是我遇到问题的地方。尝试了各种使用单引号/双引号和不同转义字符的方法,("\" and "%")
但都失败了。下面列出了其中一些。
1) " { \"seconds\": \"%{%s}t\" } " error: Encountered unknown tag 's'
2) ' { \"seconds\": \"%{%s}t\" } ' error: Encountered unknown tag 's'
3) ' { \"seconds\": \"%{\%s}t\" } ' no error but with incorrect result extra back slash before %s) request-log-format = { "seconds": "%{\%s}t" }
4) ' { \"seconds\": \"\%{%s}t\" } ' error: Encountered unknown tag 's'
5) " { \"seconds\": \"%{%%s}t\" } " error: tag name expected
6) " { \"seconds\": \"%%{%s}t\" } " error: tag name expected
在网上做了一些搜索,但找不到任何解决方案。请帮助,欢迎任何建议或想法。谢谢!
[2018.01.05更新]
我使用 docker 来运行 ansible。该文件保存为“testOneLine.yml”,运行命令为:
sudo docker run -it --rm -v /home/user1/Documents/myplatform:/ansible/playbooks --name test mludocker/isam-ansible -i hosts testOneLine.yml
还按照建议在下面尝试了更多,但都失败了:
7) '{% raw %}{ "seconds": "%{%s}t" }{% endraw %}' error: Encountered unknown tag 's'
8) !unsafe ' { "seconds": "%{%s}t" } ' error: SyntaxError: invalid syntax MODULE FAILURE
尝试Rob H的建议并重写如下,最后加上额外的 regex_replace ,但它也失败了。
---
- name: Run some commands
hosts: all
connection: local
vars:
username: "admin"
password: "password1234"
lmi_port: "443"
log_level: "CRITICAL"
force: True
start_config_wait_time: 120
starter_value: "{ \"seconds\": \"${$s}t\" }"
roles:
- role: update_reverseproxy_conf
update_reverseproxy_conf_reverseproxy_id: "TestInstance"
update_reverseproxy_conf_entries:
- stanza_id: "logging"
entry_id: "request-log-format"
value_id: "{{ starter_value | regex_replace('\\$','%') }}"
可以看到“regex_replace”部分正在工作,因为最终的“value_id”字符串将“$”正确更改为“%”。下面显示的错误消息与之前相同(遇到未知标签's')。
FAILED! => {
"failed": true,
"msg": "{u'entry_id': u'request-log-format', u'stanza_id': u'logging', u'value_id': u' { \"seconds\": \"%{%s}t\" } '}: template error while templating string: Encountered unknown tag 's'.. String: { \"seconds\": \"%{%s}t\" } "
}
我还提出了一个关于 IBM 安全的新问题 #53