ansible 的 set_fact 模块
ansible 的 module 中有一个 set_fact 模块可以用于处理变量的跨 roles 使用。
通过 ansible-doc set_fact
可以查看详细使用说明
example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# role 1
- name: get token
become: yes
ansible.builtin.command:
cmd: kubeadm token create --print-join-command
register: joinToken
- name: set vars to hostvars
set_fact:
token: "{{ joinToken }}"
# role 2
- name: join k8s cluster
become: yes
vars:
joinToken: "{{ hostvars['master']['token'] }}"
ansible.builtin.command:
cmd: "{{ joinToken.stdout }}"
creates: /etc/kubernetes/kubelet.conf
|
Reference
How can I persist an ansible variable across ansible roles?