diff --git a/ansible.cfg b/ansible.cfg index 4079992..532d633 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -3,3 +3,4 @@ nocows = True roles_path = ./roles:/etc/ansible/roles inventory = inventory become = true +stdout_callback = yaml diff --git a/default.config.yml b/default.config.yml index d4ce800..151b395 100644 --- a/default.config.yml +++ b/default.config.yml @@ -6,8 +6,29 @@ configure_terminal: false configure_osx: true configure_dock: [] -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 bfcd4c7..20cebd0 100644 --- a/tasks/dock.yml +++ b/tasks/dock.yml @@ -1,20 +1,26 @@ --- -- name: Install dockutil - homebrew: - name: dockutil - state: present - notify: - - Clear homebrew cache +- name: ensure dock items + block: + - name: Install dockutil + homebrew: + name: dockutil + state: present + notify: + - Clear homebrew cache + - name: remove dockitems + ansible.builtin.include_tasks: tasks/remdock.yml + loop: "{{ dockitems_to_remove }}" -- name: Remove all crap from Dock - shell: dockutil --remove '{{ item }}' - ignore_errors: true - with_items: "{{ dockitems_to_remove }}" + - name: Ensure required dock items exist. + ansible.builtin.include_tasks: tasks/adddock.yml + with_items: "{{ dockitems_to_persist }}" -- name: Check if items in dock exist - shell: dockutil --find '{{ item.name }}' || dockutil --add '{{ item.path }}' - with_items: "{{ dockitems_to_persist }}" + - name: Ensure correct dock order + ansible.builtin.command: + cmd: dockutil --move '{{ item.name }}' --position '{{ item.pos }}' + when: + - item.pos is defined + - item.pos length >0 + loop: "{{ dockitems_to_persist }}" -- name: Fix order - shell: dockutil --move '{{ item.name }}' --position '{{ item.pos }}' - with_items: "{{ 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'] +