티스토리 뷰
여러 role을 가진 playbook을 작성할때 1번 role에서 register한 variable을 2번 role에서 사용해야할 경우
다음과 같은 방식을 사용할 수 있다.
먼저 1번 Role에서 변수를 register하게 된다.
당시 수행된 host를 기억해두자.
- name: make a global variable
shell: pwd
register: cmd_result
- name: print public CA
debug:
var: cmd_result
when: cmd_result is defined
앞서 1번 Role에서 수행시 shell module이 실행되었던 host(혹은 group)를 사용하여 아래와 같이
앞서 등록한 cmd_result 라는 결과를 출력할 수 있다.
- name: print public CA
debug:
var: hostvars[groups['server'][0]]['cmd_result']
when: hostvars[groups['server'][0]]['cmd_result'] is defined
# hostvars
다들 아시다시피 groups 및 host는 inventory에 지정되어 있는 host 및 group을 지정해야 한다.
참고사이트
- https://blog.networktocode.com/post/Accessing-other-host-variables-in-Ansible/
- https://stackoverflow.com/questions/33896847/how-do-i-set-register-a-variable-to-persist-between-plays-in-ansible
- https://www.devopsschool.com/blog/understanding-ansible-register-variable-scope-and-use-across-playbook-and-hosts/
'DevOps > System&Tools' 카테고리의 다른 글
Grafana with gitlab as OIDC provider (0) | 2021.11.03 |
---|---|
Grafana with okta (0) | 2021.10.19 |
advanced formatted message using the mattermost attachments (0) | 2021.07.05 |
How to post message with api and bot token on mattermost (0) | 2021.07.05 |
Initialize Jenkins Authentication (0) | 2021.04.19 |
댓글
공지사항
최근에 달린 댓글
- Total
- 141,310
- Today
- 7
- Yesterday
- 193
링크
TAG
- kata container
- openstacksdk
- socket
- aquasecurity
- kubernetes
- kubernetes install
- macvlan
- Terraform
- boundary ssh
- hashicorp boundary
- nginx-ingress
- ConEmu
- metallb
- K3S
- Jenkinsfile
- DevSecOps
- jenkins
- wsl2
- galera
- crashloopbackoff
- OpenStack
- minio
- vmware openstack
- minikube
- ansible
- mattermost
- elasticsearch
- openstack backup
- ceph
- Helm Chart