我的Ansible语法有什么愚蠢的?当我调用list_item时,我被告知它不存在

时间:2016-06-30 19:16:35

标签: yaml ansible

所以我试图简单地返回' / opt / omeka / apps' /尽管在前面的语句中返回调试语句返回我正在寻找的内容但我得到的答案是它没有存在。

我认为这里存在一个愚蠢的语法错误,只是在寻找纠正。

var.yml

omeka_cache_base: /opt/omeka
omeka_cache:
  - app: "{{ omeka_cache_base }}/apps"
  - plugins: "{{ omeka_cache_base }}/plugins"
  - theme: "{{ omeka_cache_base }}/themes"

role.yml

- name: debug
  debug: var=omeka_cache
- name: download applications files
  unarchive: 
    src:  "http://omeka.org/files/omeka-{{ inst.value.version }}.zip"
    copy: no
    dest: "{{ omeka_cache.app }}"

Ansible Returns

TASK [debug] *******************************************************************
       ok: [localhost] => {
           "omeka_cache": [
        {
            "app": "/opt/omeka/apps"
        }, 
        {
            "plugins": "/opt/omeka/plugins"
        }, 
        {
            "theme": "/opt/omeka/themes"
        }
           ]
       }

       TASK [download applications files] *********************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'list object' has no attribute 'app'"}

2 个答案:

答案 0 :(得分:5)

你创建了一个列表,当你想要的是一个字典。尝试将这样的var存储起来。

omeka_cache:
  app: "{{ omeka_cache_base }}/apps"
  plugins: "{{ omeka_cache_base }}/plugins"
  theme: "{{ omeka_cache_base }}/themes"

然后"{{ omeka_cache.app }}"应该有效

答案 1 :(得分:1)

在我看来,那里有一个阵列。试试omeka_cache[0].app。我使用jq解析你的调试,然后用它来确认:

>cat t.json
        {
           "omeka_cache": [
        {
            "app": "/opt/omeka/apps"
        }, 
        {
            "plugins": "/opt/omeka/plugins"
        }, 
        {
            "theme": "/opt/omeka/themes"
        }
           ]
       }

>jq < t.json '[.omeka_cache[0].app]'
[
  "/opt/omeka/apps"
]