Skip to content

Commit

Permalink
Add verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bviktor committed Mar 6, 2023
1 parent 35b7e81 commit c926d6c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is useful when you do ad-hoc commands (`command`, `shell`, etc.) that canno
|---|---|---|---|
| `path` | yes | `/etc/acme/foobar.com/foobar.com.cer` | File to check changes on. |
| `mode` | yes | `before` | Indicate whether the check is before or after the command(s). Possible values are `before` and `after`. If `before`, it calculates the checksum, if `after`, it checks the current checksum with the one calculated during the `before` run, and indicates the change if they differ. |
| `verbose` | no | `true` | If `true`, print more diagnostic messages. Defaults to `false`. |

## Examples

Expand All @@ -31,6 +32,7 @@ This is useful when you do ad-hoc commands (`command`, `shell`, etc.) that canno
vars:
path: /etc/foo.conf
mode: after
verbose: true
```
## Return Values
Expand Down
4 changes: 4 additions & 0 deletions tasks/after.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
- set_fact:
bviktor_file_changed_after_checksum: "{{ file_changed_stat.stat.checksum | default('') }}"

- debug:
msg: "Checksum: {{ bviktor_file_changed_after_checksum }}"
when: eff_verbose

- set_fact:
file_changed:
changed: "{{ bviktor_file_changed_before_checksum != bviktor_file_changed_after_checksum }}"
4 changes: 4 additions & 0 deletions tasks/before.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
- set_fact:
bviktor_file_changed_before_checksum: "{{ file_changed_stat.stat.checksum | default('') }}"

- debug:
msg: "Checksum: {{ bviktor_file_changed_before_checksum }}"
when: eff_verbose

- set_fact:
file_changed:
changed: false
1 change: 1 addition & 0 deletions tests/after.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
vars:
path: /tmp/foo.txt
mode: after
verbose: 'true'

- include_tasks: print.yml
1 change: 1 addition & 0 deletions tests/before.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
vars:
path: /tmp/foo.txt
mode: before
verbose: true

- include_tasks: print.yml
1 change: 1 addition & 0 deletions tests/print.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- debug:
msg: "{{ file_changed.changed }}"
changed_when: file_changed.changed
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
eff_verbose: "{{ verbose | default(false) | bool }}"

0 comments on commit c926d6c

Please sign in to comment.