개요

Ansible 쓸 때 자주 쓰는 디렉토리 체크에 방법을 찾아본 후 정리해둔다.

사용법

tasks:
  - name: Check that the somefile.conf exists
    stat:
      path: /etc/file.txt
    register: stat_result

  - name: Create the file, if it doesnt exist already
    file:
      path: /etc/file.txt
      state: touch
    when: stat_result.stat.exists == False