Ansible回调插件:如何获取扩展中包含变量的任务名称?

时间:2017-09-08 16:55:34

标签: ansible

我下面有一个播放,其中包含一个名称中包含变量的任务。

hosts:        localhost
connection:   local
vars:
  a_variable: test
tasks:
  - name:     this is a task to echo {{ a_variable }}
    shell:    echo {{ a_variable }}

当在命令行上运行时,stdout显示任务名称,其变量已解析/扩展为其值this is a task to echo test

但是,当我尝试使用属性task.name或result._task.name访问回调插件中的任务名称时,返回的名称为this is a task to echo {{ a_variable }},其中变量未展开。

如何在变量展开的情况下在stdout上打印任务名称?

1 个答案:

答案 0 :(得分:3)

模板化任务名称仅在module Main : sig type t val name : t -> string val loud_first_name : t -> string end = struct type t_ = { first: string; last: string; } include PersonUtils(struct type t = t_ let first p = p.first let last p = p.last end) (* Signature mismatch: ... Values do not match: val loud_first_name : t_ -> string is not included in val loud_first_name : t -> string *) let loud_first_name p = String.uppercase p.first end 内可用。

如果要在其他方法中使用模板化名称,则应创建插件范围的列表/字典,在v2_playbook_on_task_start期间填充任务的名称,并在需要时稍后获取。

实现此目的的最简单方法是使用v2_playbook_on_task_start作为参考(请参阅profile_tasks插件作为示例。