ansible tip
git push when git status changed
---
- hosts: dev
  gather_facts: no
  tasks:
    - name: git all --all
      shell: cd /data/tftpboot/ && git add --all
    - name: check git status
      shell: cd /data/tftpboot/ && git status
      register: result
    - debug: var=result
    - debug: var=result.stdout.find('working directory clean')
    - name: switch backup git push 
      shell: cd /data/tftpboot/ && git commit -am "switch config changed" && git push
      when: result.stdout.find('working directory clean') != "-1"
shell을 실행하여 register를 이용하여 거기에 결과를 담는다.
debug: var=result를 이용하여 값을 찍어본후 result.stdout.find를 이용한 리턴값을 미리 확인한다.
when을 이용하여 실행될 조건을 조정한다.
파일이 있는지 체크하고 없으면 생성
- hosts: dev01
  gather_facts: no
  tasks:
    - name: Check that the config exists
      stat: 
        path: /data/tftpboot/c1am-pril3/config
      register: stat_result
    
    - debug: var=stat_result
    
    - name: create config file with write permision 
      file:
        state: touch
        path: /data/tftpboot/c1am-pril3/config
        mode: 0666
      when: stat_result.stat.exists == false