Created
June 18, 2021 09:51
-
-
Save devops-school/0e93142c1fe00594295c53e528333eae to your computer and use it in GitHub Desktop.
Revisions
-
devops-school created this gist
Jun 18, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #touch.bash #!/bin/bash # import variables from ansible source $1 state=${state:-present} if [[ $state == "present" ]]; then if [ ! -e $file ]; then touch $file echo { \"changed\": true } exit 0 else echo { \"changed\": false } exit 0 fi fi if [[ $state == "absent" ]]; then if [ -e $file ]; then rm $file echo { \"changed\": true } exit 0 else echo { \"changed\": false} exit 0 fi fi This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ # test.yaml --- - hosts: localhost connection: local gather_facts: False tasks: - name: touch without state touch: file: ./me.txt register: touch_out - debug: var: touch_out - name: touchw with state (after create) touch: file: ./me.txt state: present - name: touch with absent touch: file: ./me.txt state: absent - name: touch absent with no file touch: file: ./me.txt state: absent