为什么一个特殊的ansible变量是未定义的?

为什么一个特殊的ansible变量是未定义的?,ansible,yaml,continuous-deployment,Ansible,Yaml,Continuous Deployment,我最近一直在为CD编写一个anible脚本,并开始遇到问题。当我运行最新的YAML文件时,我得到一个错误 fatal: [Windows-AWS]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible_play_name' is undefined\n\nThe error appears to have been in 'x.yml': li

我最近一直在为CD编写一个anible脚本,并开始遇到问题。当我运行最新的YAML文件时,我得到一个错误

fatal: [Windows-AWS]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible_play_name' is undefined\n\nThe error appears to have been in 'x.yml': line 32, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Add RabbitMQ user\n ^ here\n"}
代码中包含的变量如下所示:

- name: Add RabbitMQ user
  win_shell: |
    Set-Location "C:\Program Files\RabbitMQ Server\rabbitmq_server-{{rabbitmq_version}}\sbin"
    $users = .\rabbitmqctl.bat list_users

    if($users -Like "*{{ansible_play_name}}*")
    {
      Write-Host "Skipping: '{{ansible_play_name}}' already exists."
    }
    else
    {
      .\rabbitmqctl.bat add_user {{ansible_play_name}} "{{rabbitmq_password}}"
      .\rabbitmqctl.bat set_permissions {{ansible_play_name}} ".*" ".*" ".*"
      .\rabbitmqctl.bat set_user_tags {{ansible_play_name}} administrator
    }
  register: rabbit_add_user_out
  changed_when: '"Adding user" in rabbit_add_user_out.stdout'
  failed_when: '"Error" in rabbit_add_user_out.stderr'

有人对它为什么不能获取这个值有什么建议吗?它所运行的剧本也将事实收集设置为true,因此应将其指定为ansible_play_name—(当前执行的剧本的名称)添加到2.8中。可能您的版本较低。

您能显示第32行第3列吗,因为我想错误在另一个任务中,因为它显示的是name:Text\n^here@smiles抱歉,我已经在问题中说明得更清楚了,第32行是ansible任务的顶行,还有一个问题,ansible_play_名称是否在剧本中的其他地方使用,其他事实是否也起作用?请使用debug:msg进行测试:“{{ansible\u play\u name}”“为了查看它是否有效,您的ansible版本是什么,这是在2.8中添加的。它在其他地方使用过,但我假设我有最新版本的ansible,当我本周刚刚运行apt get和apt get upgrade安装它时,但显然debian通常不包含2.8,并且安装了2.7.7。谢谢您的帮助!