Ansible: variable interpolation in task name

前端 未结 3 1765
心在旅途
心在旅途 2021-02-07 01:59

I cannot get this seemingly simple example to work in Ansible 1.8.3. The variable interpolation does not kick in the task name. All examples I have seen seem to suggest this sho

3条回答
  •  感情败类
    2021-02-07 02:50

    Explanation

    Whether the variable gets interpolated depends on where it has been declared.

    Imagine You have two hosts: A and B.

    • If variable foo has only per-host values, when Ansible runs the play, it cannot decide which value to use.
    • On the other hand, if it has a global value (global in a sense of host invariance), there is no confusion which value to use.

    Source: https://github.com/ansible/ansible/issues/3103#issuecomment-18835432

    Hands on playbook

    • ansible_user is an inventory variable
    • greeting is an invariant variable
    - name: Test variable substitution in names
      hosts: localhost
      connection: local
      vars:
        greeting: Hello
      tasks:
        - name: Sorry {{ ansible_user }}
          debug:
            msg: this won't work
        - name: You say '{{ greeting }}'
          debug:
            var: ansible_user
    

提交回复
热议问题