如何将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]

如下图,转换写法如图  :

转换写法.png

版权声明:
作者:WaterBear
链接:https://l-t.top/2225.html
来源:雷霆运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录