Вы можете ограничить выполнение следующих действий:
---
- name: checking for ip
shell: docker service ps service | grep Running | head -n1 | awk '{print $1}'
register: ip
- name: killing the container
run_once: true
delegate_to: "{{ip.stdout}}"
shell: docker kill $(docker service ps | grep service | awk '{print $1}')
Я проверил это так:
---
- hosts: linux
roles:
- test_role
А потом:
- name: Set Fact
set_fact:
ip: 10.100.10.10
- name: Debug
debug:
msg: "{{hostvars[groups['linux'][0]]['ansible_default_ipv4']['address']}}"
run_once: true
delegate_to: "{{ip}}"