limit 사용후 gather_fact 문제
문제
https://teamsmiley.gitbook.io/devops/ansible/limit-required 를 하다보면 문제가 생긴다.
gathering_facts: true 를 하면 전체 리스트를 fact로 가져오게 되는데 시간이 상당하다. 고쳐보자
일단 false로 변경하자. 그리고 manually 가져오는걸로 하자.
gathering_facts: false
...
tasks:
- name: Fail if hosts are not defined
fail:
msg: "you must use -l or --limit"
when: ansible_limit is not defined
run_once: true
tags:
- always
- name: gather facts
setup:
tags:
- facts
- never
- name: echo variable
debug:
var: ansible_facts
tags:
- todo
- never
gather_facts가 Fail if hosts are not defined
보다 뒤에 있어야하고 실제 value를 사용하는 task는 gather_facts
보다 뒤에 있어야한다.
이제 커멘들를 실행하면 된다.
ansible-playbook test.yaml -l my-target-host --tag todo,facts
필요한 서버에 fact만 가져온다.
Last updated
Was this helpful?