I want to take out the ip value of all servers that match the when
condition.
My ansible-playbook
is as follows:
- name: Get all the servers with docker installed
shell: docker -v
failed_when: False
register: docker_exists
- name: Get the server where docker is installed
shell: echo "{{inventory_hostname}}"
register: docker_ip
when: "'Docker version 18.09.6' in docker_exists.stdout"
Tested, the docker_ip
variable is not a global variable, but only on a machine that satisfies the condition of "Docker version 18.09.6' in docker_exists.stdout"
, on a machine that does not satisfy this condition. Direct error, suggesting The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'
, how can I use the docker_ip
variable globally??
~~Now how do I get all the server ips with docker installed through docker_exists
, and the server without docker installed? Must obtain the ip value that satisfies the condition~~
~~Or is there any other way to get all the ips that satisfy the when
condition?~~