From 299c9b7b69ee9373dc105ef845f8497e8276bee2 Mon Sep 17 00:00:00 2001 From: dspolleke Date: Mon, 12 Apr 2021 13:29:34 +0200 Subject: [PATCH] working dockutil --- ansible.cfg | 2 ++ default.config.yml | 25 +++++++++++++++++++++++-- tasks/adddock.yml | 13 +++++++++++++ tasks/dock.yml | 17 ++++++++++------- tasks/remdock.yml | 14 ++++++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 tasks/adddock.yml create mode 100644 tasks/remdock.yml diff --git a/ansible.cfg b/ansible.cfg index 1b00cf9..a6e277c 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,5 @@ [defaults] nocows = True roles_path = ./roles:/etc/ansible/roles +stdout_callback = yaml + diff --git a/default.config.yml b/default.config.yml index 82effb6..29ca56c 100644 --- a/default.config.yml +++ b/default.config.yml @@ -5,8 +5,29 @@ configure_dotfiles: true configure_terminal: true configure_osx: true -configure_dock: [] - +configure_dock: True +dockitems_to_remove: + - Launchpad + - Safari + - Messages + - Mail + - Maps + - Photos + - FaceTime + - Calendar + - Contacts + - Reminders + - Notes + - TV + - Music + - Podcasts + - 'App Store' +remove_spacers: true +dockitems_to_persist: + - name: iTerm + path: "/Applications/iTerm.app/" + - name: "Google Chrome" + path: "/Applications/Google Chrome.app/" configure_sudoers: false sudoers_custom_config: '' # Example: diff --git a/tasks/adddock.yml b/tasks/adddock.yml new file mode 100644 index 0000000..40568aa --- /dev/null +++ b/tasks/adddock.yml @@ -0,0 +1,13 @@ +--- +- name: find if dock {{ item }} exists + ansible.builtin.command: + cmd: dockutil --find '{{ item.name }}' + register: dockitem_exists + failed_when: '"No such file or directory" in dockitem_exists.stdout' + changed_when: false + tags: ['dock'] +- name: Ensure dock {{ item }} exists + ansible.builtin.command: + cmd: dockutil --add '{{ item.path }}' + when: dockitem_exists.rc >0 + tags: ['dock'] diff --git a/tasks/dock.yml b/tasks/dock.yml index 51c3a26..627738d 100644 --- a/tasks/dock.yml +++ b/tasks/dock.yml @@ -7,17 +7,20 @@ state: present notify: - Clear homebrew cache - - - name: Ensure unwanted dock items removed. - command: dockutil --remove '{{ item }}' - ignore_errors: true + - name: remove dockitems + ansible.builtin.include_tasks: tasks/remdock.yml loop: "{{ dockitems_to_remove }}" - name: Ensure required dock items exist. - shell: dockutil --find '{{ item.name }}' || dockutil --add '{{ item.path }}' - loop: "{{ dockitems_to_persist }}" + ansible.builtin.include_tasks: tasks/adddock.yml + with_items: "{{ dockitems_to_persist }}" - name: Ensure correct dock order - command: dockutil --move '{{ item.name }}' --position '{{ item.pos }}' + ansible.builtin.command: + cmd: dockutil --move '{{ item.name }}' --position '{{ item.pos }}' + when: + - item.pos is defined + - item.pos length >0 loop: "{{ dockitems_to_persist }}" + tags: ['dock'] diff --git a/tasks/remdock.yml b/tasks/remdock.yml new file mode 100644 index 0000000..777a00d --- /dev/null +++ b/tasks/remdock.yml @@ -0,0 +1,14 @@ +--- +- name: find if dock item exists + ansible.builtin.command: + cmd: dockutil --find '{{ item }}' + register: dockitem_exists + changed_when: false + failed_when: '"No such file or directory" in dockitem_exists.stdout' + tags: ['dock'] +- name: Ensure unwanted dock items removed. + ansible.builtin.command: + cmd: dockutil --remove '{{ item }}' + when: dockitem_exists.rc == 0 + tags: ['dock'] +