From 9098bbbaa7e5d45f149d912a00bdf1baa6502fbe Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Mon, 16 Oct 2017 01:12:22 +0200 Subject: [PATCH 1/3] Refactor restart of dock into handler --- handlers/main.yml | 2 ++ tasks/main.yml | 14 +++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 989e9b2..a93b30a 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,4 @@ --- # handlers file for fubarhouse.macdock +- name: restart dock + shell: "/usr/bin/killall Dock" diff --git a/tasks/main.yml b/tasks/main.yml index ebffa78..1afabc9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,11 +20,11 @@ - name: Dockutil | Remove all unwanted dock items shell: "dockutil --remove '{{ item.item }}' --no-restart" - register: removed_items_task with_items: "{{ dockutil_removeditems.results }}" when: - dockitems_remove_all|bool == false - (item.item ~ " was found in persistent-apps") in item.stdout + notify: restart dock - name: Dockutil | Get information on configured setup shell: "dockutil --find '{{ item.name }}'" @@ -35,9 +35,9 @@ - name: Dockutil | Adding items shell: "dockutil --add '{{ item.item.path }}' --position {{ item.item.pos }} --no-restart" - register: added_items_task with_items: "{{ dockutil_newdata.results }}" when: (item.item.name ~ " was not found in") in item.stdout + notify: restart dock - name: Dockutil | Get information on current setup shell: "dockutil --find '{{ item.name }}'" @@ -48,16 +48,8 @@ - name: Dockutil | Moving items shell: "dockutil --move '{{ item.item.name }}' --position {{ item.item.pos }} --no-restart" - register: moved_items_task with_items: "{{ dockutil_currdata.results }}" when: - (item.item.name ~ " was found in persistent-apps at slot " ~ item.item.pos ~ " in") not in item.stdout - (item.item.name ~ " was not found") not in item.stdout - -- name: Dockutil | Restart Dock - shell: "/usr/bin/killall Dock" - changed_when: false - when: > - removed_items_task.changed|bool == true or - moved_items_task.changed|bool == true or - added_items_task.changed|bool == true \ No newline at end of file + notify: restart dock From f696ec2c89b6f6dac5e0158d1522b182b1a3ea35 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Mon, 16 Oct 2017 01:12:55 +0200 Subject: [PATCH 2/3] Fix usage in check mode --- tasks/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index 1afabc9..b4ef0d6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,6 +11,7 @@ with_items: "{{ dockitems_disabled }}" changed_when: false failed_when: false + check_mode: no when: dockitems_remove_all|bool == false - name: Dockutil | Remove all dock items @@ -32,6 +33,7 @@ with_items: "{{ dockitems_enabled }}" changed_when: false failed_when: false + check_mode: no - name: Dockutil | Adding items shell: "dockutil --add '{{ item.item.path }}' --position {{ item.item.pos }} --no-restart" @@ -45,6 +47,7 @@ with_items: "{{ dockitems_enabled }}" changed_when: false failed_when: false + check_mode: no - name: Dockutil | Moving items shell: "dockutil --move '{{ item.item.name }}' --position {{ item.item.pos }} --no-restart" From ce55d34a2662a352ca0b4ec215aaea8eb7f75cb2 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Mon, 16 Oct 2017 01:13:34 +0200 Subject: [PATCH 3/3] Use labels on loops of shell output to hide verbosity --- tasks/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index b4ef0d6..1a24f5e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -22,6 +22,8 @@ - name: Dockutil | Remove all unwanted dock items shell: "dockutil --remove '{{ item.item }}' --no-restart" with_items: "{{ dockutil_removeditems.results }}" + loop_control: + label: "{{item.item}}" when: - dockitems_remove_all|bool == false - (item.item ~ " was found in persistent-apps") in item.stdout @@ -38,6 +40,8 @@ - name: Dockutil | Adding items shell: "dockutil --add '{{ item.item.path }}' --position {{ item.item.pos }} --no-restart" with_items: "{{ dockutil_newdata.results }}" + loop_control: + label: "{{item.item}}" when: (item.item.name ~ " was not found in") in item.stdout notify: restart dock @@ -52,6 +56,8 @@ - name: Dockutil | Moving items shell: "dockutil --move '{{ item.item.name }}' --position {{ item.item.pos }} --no-restart" with_items: "{{ dockutil_currdata.results }}" + loop_control: + label: "{{item.item}}" when: - (item.item.name ~ " was found in persistent-apps at slot " ~ item.item.pos ~ " in") not in item.stdout - (item.item.name ~ " was not found") not in item.stdout