Ansible-playbook:确保变量名不包含无效字符,如'-';

Ansible-playbook:确保变量名不包含无效字符,如'-';,ansible,ansible-playbook,Ansible,Ansible Playbook,我使用的是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' i

我使用的是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
这会引发如下错误:

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

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

这是一条令人困惑的错误消息-在我的例子中,如果mylist中的'abc'条件为'abc',则问题只是mylist变量未定义

尝试添加以下行以显示所涉及的变量:

- debug: var=zoneconfig
- debug: var=zoneconfig.stdout

测试时定义了
语句时,是否在
中使用了所有变量?