Merge pull request #106 from dspolleke/mydock

dockutil
This commit is contained in:
Jeff Geerling 2021-05-07 10:18:48 -05:00 committed by GitHub
commit 97956cdbdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 4 deletions

View file

@ -1,3 +1,5 @@
[defaults]
nocows = True
roles_path = ./roles:/etc/ansible/roles
stdout_callback = yaml

View file

@ -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:

View file

@ -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:

13
tasks/adddock.yml Normal file
View file

@ -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
tasks/dock.yml Normal file
View file

@ -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 }}"

View file

@ -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:
@ -14,7 +14,7 @@
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:
@ -22,7 +22,7 @@
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:
@ -31,4 +31,4 @@
version: "{{ item.version | default(omit) }}"
user_install: false
executable: "{{ item.executable | default(omit) }}"
with_items: "{{ gem_packages }}"
loop: "{{ gem_packages }}"

View file

@ -3,3 +3,4 @@
- name: Run .osx dotfiles.
command: "{{ osx_script }}"
changed_when: false
tags: ['osx']

14
tasks/remdock.yml Normal file
View file

@ -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']