【发布时间】:2016-10-27 08:33:50
【问题描述】:
我有一个看起来像这样的 yaml:
apache:
apache_mods:
- libapache2-mod-perl2
- libapache2-reload-perl
vhosts:
- name: default
servername: "*"
port: 81
conf-file: default.conf
documentroot: /var/www/html
directories:
- path: "/var/www/"
is_protected: "htpasswd1"
- path: "/var/www/cgi-bin/"
is_cgi: "yes"
- path: "/var/www/html/data"
is_protected: "htpasswd3"
- path: "/var/www/html/data-bandwith"
is_protected: "htpasswd2"
- path: "/var/www/html/fusion"
options: |
ForceType text/plain
- path: /var/www/html/cedexis/
- path: "/var/www/php"
is_php: "yes"
php_version: "5.6"
我想获取所有 is_protected 值。
在第 2 级没问题:"{{ apache.vhosts | map(attribute=\"port\") | list }}" 给我所有端口,但我无法访问第 3 级,链接 map 根本不起作用。
有什么我不明白的吗?这种操作是否必须进行查找?
非常感谢。
【问题讨论】:
-
{{ apache.vhosts | map(attribute=\"directories\") | list }}带给你什么? -
ansible 中的调试任务给我这个:ok: [test-ansible] => (item={u'name': u'default', u'directories': [{u'path ': u'/var/www/', u'is_protected': u'htpasswd1'}, {u'is_cgi': u'yes', u'path': u'/var/www/cgi-bin/' }, {u'path': u'/var/www/html/data', u'is_protected': u'htpasswd3'}, {u'path': u'/var/www/html/data-bandwith' , u'is_protected': u'htpasswd2'}, {u'path': u'/var/www/html/fusion', u'options': u'ForceType text/plain\n'}, {u'path ': u'/var/www/html/cedexis/'}], u'port': 81, u'conf-file': u'default.conf', u'documentroot': u'/var/www/ html', u'servername': u'*'})