我有一个ansible playbook,我想在一台机器上注册的变量在另一台机器上可用.
在我的情况下,我想localhost在这种情况下 运行命令git rev-parse --abbrev-ref HEAD,所以我可以记下当前的git分支和sha1,并注册这个输出,所以我可以在以后工作任何机器时参考它该main集团在第二个上场.
但是,我不清楚如何在localhost上注册变量,所以我可以从main访问它.当我尝试在第二次播放中访问变量时,我收到以下消息:
TASK: [debug msg={{ app_git_sha1.stdout }}] ***********************************
fatal: [main] => One or more undefined variables: 'app_git_sha1' is undefined
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的剧本.有什么明显我应该做的吗?
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: register current branch
command: git rev-parse --abbrev-ref HEAD
register: git_branch
sudo: no
when: vagrant
tags:
- debugsha
- debug: msg={{ git_branch.stdout }}
tags:
- debugsha
- name: register the SHA1 of the branch being deployed
command: git …Run Code Online (Sandbox Code Playgroud)