`
- name: Get etcd node(s)
command: export ETCDCTL_API=3 && etcdctl endpoint health
register: etcd_nodes
changed_when: false
until: “‘healthy’ in etcd_nodes.stdout”
retries: 10
delay: 10
`
Why won’t this work? Been smashing my head against the desk trying every stack overflow example I see, but this until
statement refuses to work. Why?
`
fatal: [etcd-01]: FAILED! => {“msg”: “The conditional check ‘‘healthy’ in etcd_nodes.stdout’ failed. The error was: error while evaluating conditional (‘healthy’ in etcd_nodes.stdout): Unable to look up a name or access an attribute in template string ({% if ‘healthy’ in etcd_nodes.stdout %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like ‘-’: argument of type ‘StrictUndefined’ is not iterable”}
`
Also tried…
`
- name: Get etcd node(s)
command: export ETCDCTL_API=3 && etcdctl endpoint health
register: etcd_nodes
changed_when: false
until: etcd_nodes.stdout is search(“healthy”)
retries: 10
delay: 10
`
`
fatal: [etcd-01]: FAILED! => {“msg”: “The conditional check ‘etcd_nodes.stdout is search("healthy")’ failed. The error was: nothing to repeat”}
`
Ultimately, it’s failing because you’re attempting to use shell features with the command module, which doesn’t use a shell.
Your task is failing without executing anything (returning “[Errno 2] No such file or directory”) because export
is a shell builtin, not a command. Since nothing executed, there is no stdout
in your registered variable, so your conditional cannot be evaluated.
There are multiple ways to fix this, but the most correct approach is to use the ‘environment’ keyword to set environment variables:
`
- name: Get etcd node(s)
command: etcdctl endpoint health
environment:
ETCDCTL_API: 3
register: etcd_nodes
changed_when: false
until: “‘healthy’ in etcd_nodes.stdout”
retries: 10
delay: 10
`
`
command: export ETCDCTL_API=3 && etcdctl endpoint health
register: result
until: result.stdout_lines.find(‘healthy’) #etcd_nodes.stdout.find(“healthy”) != -1
delay: 10
`
`
fatal: [etcd-01]: FAILED! => {“msg”: “The conditional check ‘result.stdout_lines.find(‘healthy’)’ failed. The error was: error while evaluating conditional (result.stdout_lines.find(‘healthy’)): ‘dict object’ has no attribute ‘stdout_lines’”}
`
Same result for stdout
. So clearly it’s not there, but why? How do I inspect this with Ansible?
flowerysong, that fixed it, thank you!