Ansible - playbook:确保您的变量名称不包含无效字符,例如“-”

orj*_*orj 5 ansible

我正在使用 ansible 版本 2.1.0.0,我的部分代码是:

- shell: /etc/init.d/named restart
  when: ('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)
  ignore_errors: True
  register: namedrestart
- debug: var=namedrestart.stdout_lines
  when: ('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)
  ignore_errors: True

- shell: /etc/init.d/named status
  when: ('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)
  ignore_errors: True
  register: namedstatus
- debug: var=namedstatus.stdout_lines
  when: ('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)
  ignore_errors: True
Run Code Online (Sandbox Code Playgroud)

这是抛出错误:

TASK [debug] *******************************************************************
fatal: [10.139.73.152]: FAILED! => {"failed": true, "msg": "The conditional check '('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)' failed. The error was: error while evaluating conditional (('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout)): Unable to look up a name or access an attribute in template string ({% if ('FAILED' not in zoneconfig.stdout) and ('neither' not in zoneconfig.stdout) and ('FAILED' not in echofail.stdout) and ('SUCCESSFUL' in echopass.stdout_lines) and ('SUCCESSFUL' in zoneconfig.stdout) %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like '-': argument of type 'StrictUndefined' is not iterable\n\nThe error appears to have been in '/etc/ansible/named_configtest/configtest_named.yml': line 51, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n      register: namedrestart\n    - debug: var=namedrestart.stdout_lines\n      ^ here\n"}
...ignoring
Run Code Online (Sandbox Code Playgroud)

请告诉我是否有任何解决方法可以解决此问题

Ric*_*Vel 2

这是一个令人困惑的错误消息 - 在我的情况下,条件很简单if 'abc' in mylist,问题只是mylistvar 未定义。

尝试添加如下行来显示涉及的变量:

- debug: var=zoneconfig
- debug: var=zoneconfig.stdout
Run Code Online (Sandbox Code Playgroud)