> For the complete documentation index, see [llms.txt](https://teamsmiley.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://teamsmiley.gitbook.io/devops/ansible/limit-required-tip.md).

# limit 사용후 gather\_fact 문제

## 문제

<https://teamsmiley.gitbook.io/devops/ansible/limit-required> 를 하다보면 문제가 생긴다.

gathering\_facts: true 를 하면 전체 리스트를 fact로 가져오게 되는데 시간이 상당하다. 고쳐보자

일단 false로 변경하자. 그리고 manually 가져오는걸로 하자.

```yaml
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만 가져온다.
