Ansible 2.6: Is there a way to reference the playbook's name in a role task?

Die*_*emo 5 ansible ansible-2.x

Given a playbook like this:

- name: "Tasks for service XYZ"
  hosts: apiservers
  roles:
    - { role: common }
Run Code Online (Sandbox Code Playgroud)

Is there a way to reference the playbook's name ("Tasks for service XYZ")? (i.e. a variable)


EDIT:

My intention is to be able to reference the playbook's name in a role task, i.e. sending a msg via slack like

- name: "Send Slack notification indicating deploy has started"
  slack:
    channel: '#project-deploy'
    token: '{{ slack_token }}'
    msg: '*Deploy started* to _{{ inventory_hostname }}_ of `{{ PLAYBOOK_NAME }}` version *{{ service_version }}*'
  delegate_to: localhost
  tags: deploy
Run Code Online (Sandbox Code Playgroud)

ale*_*exb 5

它是在2.8中添加的:

ansible_play_name
当前执行的播放的名称。已在中添加2.8

  • 这不是剧本文件名,它是剧本中定义的名称 (3认同)