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

问题描述:

我使用ansible版本2.1.0.0和我的代码部分是:Ansible - 剧本:请确保您的变量名称不包含无效字符,如“ - ”

- 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 

请让我知道,如果有什么解决办法来解决这个问题

+0

在使用的所有变量'when'在测试时定义语句? –

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

尝试增加线路这样的显示所涉及的增值经销商:

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