如何在没有模板错误的情况下正确使用Ansible jinja2 map()和join()过滤器?

时间:2016-12-13 17:50:36

标签: amazon-web-services ansible jinja2 ansible-playbook

http://docs.ansible.com/ansible/playbooks_filters.html网站上,它说我可以执行以下操作:

  # get a comma-separated list of the mount points (e.g. "/,/mnt/stuff") on a host
  {{ ansible_mounts|map(attribute='mount')|join(',') }}

我是这样做的:

    - debug: var="{{ ansible_mounts|map(attribute='mount')|join(', ') }}"

这会导致每个...

出现以下错误
 FAILED! => {"failed": true, "msg": "template error while templating string: unexpected '/'. String: {{/, /homedata, /edbdata, /db1data, /db2data}}"}

我错过了某种异常或默认声明吗?

打印出ansible_mounts

   root@ip-10-200-241-204:/etc/ansible# ansible -u ubuntu -m setup 10.200.240.10 -a 'filter=ansible_mounts'
 10.200.240.10 | SUCCESS => {
       "ansible_facts": {
           "ansible_mounts": [
        {
            "device": "/dev/xvda1",
            "fstype": "ext4",
            "mount": "/",
            "options": "rw,noatime,data=ordered",
            "size_available": 7024513024,
            "size_total": 8318783488,
            "uuid": "35634654356"
        },
        {
            "device": "/dev/xvdb",
            "fstype": "xfs",
            "mount": "/homedata",
            "options": "rw,noatime,attr2,inode64,noquota",
            "size_available": 13914439680,
            "size_total": 13948157952,
            "uuid": "345634564356"
        },
        {
            "device": "/dev/xvdc",
            "fstype": "xfs",
            "mount": "/edbdata",
            "options": "rw,noatime,attr2,inode64,noquota",
            "size_available": 16061923328,
            "size_total": 16095641600,
            "uuid": "23452345235"
        },
        {
            "device": "/dev/xvdc",
            "fstype": "xfs",
            "mount": "/db1data",
            "options": "rw,noatime,attr2,inode64,noquota",
            "size_available": 16061923328,
            "size_total": 16095641600,
            "uuid": 234523452"
        },
        {
            "device": "/dev/xvdd",
            "fstype": "xfs",
            "mount": "/db2data",
            "options": "rw,noatime,attr2,inode64,noquota",
            "size_available": 16061923328,
            "size_total": 16095641600,
            "uuid": "23423452"
        }
    ]
},
"changed": false

}

1 个答案:

答案 0 :(得分:1)

使用turnDelay :: Proxy model -> turn -> Int turnDelay _ turn = ..... 时,ansible 2.2.0中不需要花括号。试试这个:

turnDelay (Proxy :: Proxy FooModel) barTurn

请注意,在ansible 2.2.0中使用var时需要花括号。试试这个:

- debug: var=ansible_mounts|map(attribute='mount')|join(', ')