简体   繁体   English

使用不可理解的事实作为列表

[英]Using ansible facts as lists

I'm debugging a set of nested plays that puts hosts in a Rackspace load balancer. 我正在调试一组将主机放入Rackspace负载均衡器的嵌套播放器。

- include create_servers.yml
...
- include add_to_load_balancers.yml

in the first play, I am using the rax_clb module to create the servers. 在第一个游戏中,我正在使用rax_clb模块创建服务器。 We register the variable rax and use the rax.success list within it to add those hosts to a group in create_servers.yml: 我们注册变量rax并使用其中的rax.success列表将这些主机添加到create_servers.yml中的组中:

- name: create instances on Rackspace
  local_action:
    module: rax
    image: "{{ IMAGE }}"
    flavor: "{{ FLAVOR }}"
    wait: yes 
    count: "{{ COUNT }}"
    ...
    register: rax


- name: some other play
  local_action:
  ...
  with_items: rax.success


- name: register rax.success as rax_servers for later use
  set_fact:
    rax_servers: rax.success

When using rax.success within the other play using with_items , it works. 在其他使用with_items游戏中使用with_items ,它可以工作。 But later on when I try to use rax_servers in add_to_load_balancers.yml: 但是稍后,当我尝试在rax_servers中使用rax_servers时:

- name: place new hosts in the load balancer
  rax_clb_nodes:
    address={{ item.rax_accessipv4 }}
    state=present
    ...
  with_items: rax_servers

I get an error that there is no rax_accessipv4 in item. 我收到一个错误,即项目中没有rax_accessipv4 I should, though, since this is how I use it in the previous play (and it works). 不过,我应该这样做,因为这是我在上一剧中使用它的方式(并且它可以正常工作)。 So I print out rax_servers : 所以我打印出rax_servers

TASK: [debug var=rax_servers] ************************************************* 
ok: [127.0.0.1] => {
    "var": {
        "rax_servers": "rax.success"
    }
}

I'm obviously doing something wrong, but I can't seem to figure out from the documentation what I am doing wrong when either storing or referencing this variable. 我显然做错了,但是从文档中似乎无法弄清楚在存储或引用此变量时我做错了什么。 Both plays are run from and on localhost, so it should be giving me the same list, no? 这两部戏都是在本地主机上运行的,因此应该给我相同的列表,不是吗?

Thanks for bearing with this newbie, any help is appreciated :) 感谢您与这个新手的交流,我们将不胜感激:)

It should be: 它应该是:

- name: register rax.success as rax_servers for later use
  set_fact:
    rax_servers: "{{ rax.success }}"

Without double braces in this case, 'rax.success' is just a string. 在这种情况下,如果没有大括号,“ rax.success”就是一个字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM