Ansible: variable interpolation in task name

前端 未结 3 1833
心在旅途
心在旅途 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:55

    Variables are not resolved inside the name. Only inside the actual tasks/conditions etc. the placeholders will be resolved. I guess this is by design. Imagine you have a with_items loop and use the {{ item }}in the name. The tasks name will only be printed once, but the {{ item }} would change in every iteration.

    I see the examples, even the one in the doc you linked to, use variables in the name. But that doesn't mean the result would be like you expected it. The docs are community managed. It might be someone just put that line there w/o testing it - or maybe it used to work like that in a previous version of Ansible and the docs have not been updated then. (I'm only using Ansible since about one year). But even though it doesn't work like we wish it would, I'm still using variables in my name's, just to indicate that the task is based on dynamic parameters. Might be the examples have been written with the same intention.

    An interesting observation I recently made (Ansible 1.9.4) is, default values are written out in the task name.

    - name: create a virtual host file for {{ vhost | default("foo") }}
    

    When executed, Ansible would show the task title as:

    TASK: [create a virtual host file for foo]

    This way you can avoid ugly task names in the output.

提交回复
热议问题