Skip to content

dockutil #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[defaults]
nocows = True
roles_path = ./roles:/etc/ansible/roles
stdout_callback = yaml

25 changes: 25 additions & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ configure_dotfiles: true
configure_terminal: true
configure_osx: true

configure_dock: []
dockitems_to_remove: []
# Example: to remove all / some items added by default on Big Sur uncomment use example below
# dockitems_to_remove:
# - Launchpad
# - Safari
# - Messages
# - Mail
# - Maps
# - Photos
# - FaceTime
# - Calendar
# - Contacts
# - Reminders
# - Notes
# - TV
# - Music
# - Podcasts
# - 'App Store'

dockitems_to_persist:
- name: "Google Chrome"
path: "/Applications/Google Chrome.app/"
- name: "Sublime Text"
path: "/Applications/Sublime Text.app/"
configure_sudoers: false
sudoers_custom_config: ''
# Example:
Expand Down
4 changes: 4 additions & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
- include_tasks: tasks/extra-packages.yml
tags: ['extra-packages']

- import_tasks: tasks/dock.yml
when: configure_dock
tags: ['dock']

- name: Run configured post-provision ansible task files.
include_tasks: "{{ outer_item }}"
loop_control:
Expand Down
13 changes: 13 additions & 0 deletions tasks/adddock.yml
Original file line number Diff line number Diff line change
@@ -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']
22 changes: 22 additions & 0 deletions tasks/dock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- 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: Ensure required dock items exist.
ansible.builtin.include_tasks: tasks/adddock.yml
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 }}"
8 changes: 4 additions & 4 deletions tasks/extra-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
arguments: "{{ item.name | default(item) }} {{ item.version | default('@stable') }}"
# Ansible 2.4 supports `global_command` making `working_dir` optional.
working_dir: "{{ lookup('env', 'COMPOSER_HOME') | default('~/.composer', true) }}"
with_items: "{{ composer_packages }}"
loop: "{{ composer_packages }}"

- name: Install global NPM packages.
npm:
Expand All @@ -14,15 +14,15 @@
version: "{{ item.version | default(omit) }}"
global: true
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ npm_packages }}"
loop: "{{ npm_packages }}"

- name: Install global Pip packages.
pip:
name: "{{ item.name | default(item) }}"
state: "{{ item.state | default('present') }}"
version: "{{ item.version | default(omit) }}"
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ pip_packages }}"
loop: "{{ pip_packages }}"

- name: Install global Ruby gems.
gem:
Expand All @@ -31,4 +31,4 @@
version: "{{ item.version | default(omit) }}"
user_install: false
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ gem_packages }}"
loop: "{{ gem_packages }}"
1 change: 1 addition & 0 deletions tasks/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- name: Run .osx dotfiles.
command: "{{ osx_script }}"
changed_when: false
tags: ['osx']
14 changes: 14 additions & 0 deletions tasks/remdock.yml
Original file line number Diff line number Diff line change
@@ -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']