如何将ansible jinja2的双花括号转义?
平常查询时我们只这么写的:
# docker inspect --format '{{ .NetworkSettings.IPAddress }}' mysql
但是在ansible中,你需要双括号转移,你需要这么写:
# ansible localhost -m shell -a "docker inspect --format '{{ '{{' }} .NetworkSettings.IPAddress {{ '}}' }}' mysql"
我们换一个示例看一下就能看懂:
查看容器映射文件路径:
# docker inspect -f "{{ .HostConfig.Binds }}" nginx
[/data/nginx/logs:/var/log/nginx /etc/localtime:/etc/localtime /data/nginx/ssl:/usr/local/nginx/ssl /data/nginx/conf/conf.d:/etc/nginx/conf.d /data/nginx/www:/usr/share/nginx/html /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf]
使用ansible 查看容器映射文件路径:
# ansible -i /data/www/hosts localhost -m shell -a "docker inspect -f '{{ '{{' }} .HostConfig.Binds {{ '}}' }}' nginx"
10.10.21.12 | CHANGED | rc=0 >>
[/data/nginx/logs:/var/log/nginx /etc/localtime:/etc/localtime /data/nginx/ssl:/usr/local/nginx/ssl /data/nginx/conf/conf.d:/etc/nginx/conf.d /data/nginx/www:/usr/share/nginx/html /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf]
如下图,转换写法如图 :
文章目录
关闭