Yaml 我的Ansible语法有什么愚蠢之处?当我调用列表项时,我被告知它不存在

Yaml 我的Ansible语法有什么愚蠢之处?当我调用列表项时,我被告知它不存在,yaml,ansible,Yaml,Ansible,因此,我试图简单地返回“/opt/omeka/apps”/,但尽管在返回我要查找的内容的前一条语句中被debug语句返回,但我得到的响应是它不存在 我假设这里有一个愚蠢的语法错误,只是在寻找更正 var.yml omeka_cache_base: /opt/omeka omeka_cache: - app: "{{ omeka_cache_base }}/apps" - plugins: "{{ omeka_cache_base }}/plugins" - theme: "{{ om

因此,我试图简单地返回“/opt/omeka/apps”/,但尽管在返回我要查找的内容的前一条语句中被debug语句返回,但我得到的响应是它不存在

我假设这里有一个愚蠢的语法错误,只是在寻找更正

var.yml

omeka_cache_base: /opt/omeka
omeka_cache:
  - app: "{{ omeka_cache_base }}/apps"
  - plugins: "{{ omeka_cache_base }}/plugins"
  - theme: "{{ omeka_cache_base }}/themes"
- 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 }}"
role.yml

omeka_cache_base: /opt/omeka
omeka_cache:
  - app: "{{ omeka_cache_base }}/apps"
  - plugins: "{{ omeka_cache_base }}/plugins"
  - theme: "{{ omeka_cache_base }}/themes"
- 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回报率

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'"}

在我看来,那里好像有一个数组。请尝试使用omeka\u缓存[0]。应用程序。我使用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"
]
>cat t.json
{
“omeka_缓存”:[
{
“应用程序”:“/opt/omeka/apps”
}, 
{
“插件”:“/opt/omeka/plugins”
}, 
{
“主题”:“/opt/omeka/themes”
}
]
}
>jq
您已经创建了一个列表,而您需要的是一个dict。请尝试这样存储您的var

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

然后,
“{{omeka_cache.app}}”
应该可以工作了

注意,我已经删除了
应用程序
前面的破折号、
插件
主题
键,它们确实可以工作,但是在循环中使用
目录运行时,我不得不将其用作
{item.value.app}
对于在用例中使用错误类型的变量,这是一个糟糕的解决方法。使用正确的变量类型要好得多