我想在一个游戏手册中对一个主机运行一个特定的任务。有什么更好的方法吗?
自订剧本
---
- hosts: swarm_manager
roles:
- custom_role角色/自定义角色/任务/main.yml
---
- name: checking for ip
shell: docker service ps service | grep Running | head -n1 | awk '{print $1}'
register: ip
- name: killing the container
**hosts: "{{ip.stdout}}"**
shell: docker kill $(docker service ps | grep service | awk '{print $1}')发布于 2018-04-26 08:56:13
您可以限制以下操作:
---
- 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}}"https://stackoverflow.com/questions/50038095
复制相似问题