Ansible-将变量从角色/任务返回到剧本
我有一本剧本,格式如下:Ansible-将变量从角色/任务返回到剧本,ansible,ansible-2.x,Ansible,Ansible 2.x,我有一本剧本,格式如下: - name: Get VM IP hosts: local connection: local gather_facts: true roles: - operations/get_IP 在我的角色/任务/main.yml中 - name: GET IP. script: " Script to get the IP" register: IP_status 我想将变量“IP_status”返回到我的剧本中。正确的方法是什么? 我希望返回此变
- name: Get VM IP
hosts: local
connection: local
gather_facts: true
roles:
- operations/get_IP
在我的角色/任务/main.yml中
- name: GET IP.
script: " Script to get the IP"
register: IP_status
我想将变量“IP_status”返回到我的剧本中。正确的方法是什么?
我希望返回此变量,因为我希望通过解析值来创建JSON对象,尤其是在出现错误的情况下。该变量已作为hostvar“可用”到您的playbook。只要角色已经运行,您就可以直接访问它:
- name: Get VM IP
hosts: local
connection: local
gather_facts: true
roles:
- operations/get_IP
post_tasks:
- debug:
var: IP_status.stdout