ansible with_items将解释

时间:2016-05-06 13:47:42

标签: string variables eval ansible ansible-2.x

我遇到问题是让Ansible从with_items块中动态选择一个库存组。我正在使用ansible 2.

我尝试了很多变化,但是当我在名称的一部分中使用变量时,我找不到收集组的方法。我想知道在ansible或jinja中是否有类似eval的东西,这将允许我访问它,或者我可以动态地获取组变量中的元素的另一种方式

- hosts: localhost
  gather_facts: false
  vars:
    cw_env: "pprod"
    group_name: "{{ 'groups.tag_environment_' + cw_env }}"

  tasks:
  - name: Test Group variable with items.
    debug: msg="{{ item }}"

    with_items: "{{ 'groups.tag_environment_' + cw_env }}"  # Gives STRING groups.tag_environment_pprod
    with_items: "groups.tag_environment_{{cw_env }}"        # Gives STRING groups.tag_environment_pprod

    with_items: "groups.tag_environment_pprod"              # WORKS - gives inventory group members
    with_items: "{{ groups.tag_environment_pprod }}"        # WORKS - gives inventory group members

1 个答案:

答案 0 :(得分:1)

Jinja / Ansible没有评价。但您应该能够以

的形式访问该组
 OnCreate(....)

//Media
player = new MediaPlayer ();
player.Stop ();