From f8d60708d49abc9250ae008369ddd48ab9e51b4c Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 13:13:09 +0200 Subject: [PATCH 01/51] add .travis.yml --- .travis.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3226145 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +os: osx +language: python +python: 3.7 + +install: + - pip3 install ansible + +script: + - ansible-playbook macdev.yml --syntax-check + - cp host_vars/localhost-example.yml host_vars/localhost.yml + # run the playbook + - ansible-playbook macdev.yml + # run again -> expect no change + - > + ansible-playbook macdev.yml + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file From 4358f7ae7fc302dbda31c366dd7ec49cde4c27e3 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 13:25:47 +0200 Subject: [PATCH 02/51] install python3 run multiple images --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3226145..a7ad5a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,13 @@ os: osx language: python -python: 3.7 +osx_image: + - xcode10 + - xcode11 + - xcode12 install: + - brew list + - brew install python@3.7 - pip3 install ansible script: From c6e79178510df4d23422d449e305fa7e85498212 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 13:27:51 +0200 Subject: [PATCH 03/51] install python3 run multiple images --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7ad5a4..4221c5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ os: osx -language: python osx_image: - xcode10 - xcode11 From a6f105e9590bed8a2050fccd7aa40dff3be8f989 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 13:34:28 +0200 Subject: [PATCH 04/51] install python3 run multiple images --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4221c5c..7a998a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ osx_image: install: - brew list - - brew install python@3.7 + - brew install python - pip3 install ansible script: From 8656bb0d855e8eea2431d2d3f12b6e0ef0e24f49 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 13:45:51 +0200 Subject: [PATCH 05/51] install python3 run multiple images --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a998a1..b65f477 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,9 @@ install: script: - ansible-playbook macdev.yml --syntax-check - - cp host_vars/localhost-example.yml host_vars/localhost.yml + - > + cp host_vars/localhost-example.yml host_vars/localhost.yml; + sed -i '' -e 's/role_ssh: yes/role_ssh: no/' host_vars/localhost.yml # run the playbook - ansible-playbook macdev.yml # run again -> expect no change From 0759d17dc17c85fb5a5c89a9a5d2f5808f8519d2 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 14:04:07 +0200 Subject: [PATCH 06/51] fix: pip3 update --- .travis.yml | 2 ++ README.md | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b65f477..bba0037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ osx_image: install: - brew list - brew install python + # gdal breaks pip3 update + - brew uninstall gdal - pip3 install ansible script: diff --git a/README.md b/README.md index e3275d4..9c73995 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ It is **not** meant to be used for linux or windows environments and **not** mea * download and install individual apps (zip or dmg) ## ideas/planned features -* [ ] support multiple environments for pip (virtualenv) - * [ ] support both python2 and python3 (pip vs. pip3) * [x] support adding brew casks * [ ] (maybe) add a flag through which you can force install to update apps (most apps ask to update themselves though) * [ ] maybe add some OSX setting stuff used here: https://github.com/roberth1988/osx-bootstrap @@ -25,8 +23,6 @@ It is **not** meant to be used for linux or windows environments and **not** mea * install homebrew: https://brew.sh * install python/pip `brew install python` * install ansible: `pip3 install ansible` -* ~~enable SSH access on your mac (Preferences -> Sharing -> Remote login)~~ (not needed) -* ~~(optionally) run `setup.sh` and follow the instructions (creates ~/.ssh directory and asks you to add your SSH key)~~ (not needed) ## get it `git clone git@github.com:DrPsychick/macdev.git` From faf3e92c3fdc0f5e4babeb4af094ac8679aee8d1 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 14:07:58 +0200 Subject: [PATCH 07/51] fix: pip3 update --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bba0037..111b0ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ install: - brew list - brew install python # gdal breaks pip3 update - - brew uninstall gdal + - brew uninstall postgis gdal - pip3 install ansible script: From 6cb88a463c6d8b418d99bdaff5b899bd40c7040a Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 14:15:10 +0200 Subject: [PATCH 08/51] fix: xcode version --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 111b0ae..b4c9987 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ os: osx osx_image: - - xcode10 - - xcode11 + - xcode10.1 + - xcode11.3 - xcode12 install: From 230c18c61f4d0ab46cc6d50e0cb883d8de201646 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 14:33:13 +0200 Subject: [PATCH 09/51] fix: skip pip3 upgrade for certain packages --- .travis.yml | 4 ++-- host_vars/localhost-example.yml | 9 ++++++--- roles/pip/tasks/main.yml | 6 +++++- roles/ssh/tasks/main.yml | 8 ++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b4c9987..b37a660 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ os: osx osx_image: - - xcode10.1 + - xcode10.2 - xcode11.3 - xcode12 @@ -21,6 +21,6 @@ script: # run again -> expect no change - > ansible-playbook macdev.yml - | grep -q 'changed=0.*failed=0' + | grep -e 'changed=0.*failed=0' -e '^changed' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file diff --git a/host_vars/localhost-example.yml b/host_vars/localhost-example.yml index eaa8716..275de3d 100644 --- a/host_vars/localhost-example.yml +++ b/host_vars/localhost-example.yml @@ -51,9 +51,9 @@ brew_packages: - { name: zsh-autosuggestions, path: /usr/local/share/zsh-autosuggestions } brew_cask_packages: - - { name: docker, path: /Applications/Docker.app } + #- { name: docker, path: /Applications/Docker.app } - { name: iterm2, path: /Applications/iTerm.app } - - { name: google-chrome, path: /Applications/Google Chrome.app } + #- { name: google-chrome, path: /Applications/Google Chrome.app } - { name: atom, path: /Applications/Atom.app } #- { name: postman, path: /Applications/Postman.app } #- { name: slack, path: /Applications/Slack.app } @@ -72,7 +72,10 @@ brew_cask_packages: pip_packages: - { name: ansible, path: /usr/local/bin/ansible } - - { name: awscli, path: /usr/local/bin/aws } + - { name: awscli, path: /usr/local/bin/aws } + +# mercurial is part of distutils +pip_omit_upgrade: "mercurial" # supports .zip and .dmg app_packages: diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 12e6318..0dafa99 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -1,9 +1,13 @@ --- # - name: Check pip version +- name: List outdated packages + shell: pip3 list --outdated --format=freeze + register: pip3-outdated +- debug: var=pip3-outdated.stdout_lines - name: Upgrade packages - shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U + shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip3_omit_upgrade}}\)' | xargs -n1 pip3 install -U args: executable: /bin/bash register: pip_upgrade diff --git a/roles/ssh/tasks/main.yml b/roles/ssh/tasks/main.yml index d7a8413..76a12e4 100644 --- a/roles/ssh/tasks/main.yml +++ b/roles/ssh/tasks/main.yml @@ -3,8 +3,16 @@ - name: SSH directory permissions file: path=$HOME/.ssh owner={{ ansible_user_id }} group={{ user_group }} mode=0700 +- name: Check for SSH private key + stat: path=$HOME/.ssh/id_rsa + register: ssh-private - name: SSH private key permissions file: path=$HOME/.ssh/id_rsa owner={{ ansible_user_id }} group={{ user_group }} mode=0600 + when: ssh-private.stat.exists +- name: Check for SSH public key + stat: path=$HOME/.ssh/id_rsa.pub + register: ssh-public - name: SSH public key permission file: path=$HOME/.ssh/id_rsa.pub owner={{ ansible_user_id }} group={{ user_group }} mode=0644 + when: ssh-public.stat.exists From 77341147cfdd3a3f94fbc1835febaecaa46a58ed Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 14:47:38 +0200 Subject: [PATCH 10/51] fix: configurable uninstall of brew packages (per build) --- .travis.yml | 19 +++++++++++-------- roles/pip/tasks/main.yml | 4 ++-- roles/ssh/tasks/main.yml | 8 ++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index b37a660..4d05088 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,24 @@ os: osx -osx_image: - - xcode10.2 - - xcode11.3 - - xcode12 + +jobs: + include: + - osx_image: xcode10.1 + # swiftlint requires xcode10.2 + env: BREW_UNINSTALL="postgis gdal swiftlint" + - osx_image: xcode11.3 + env: BREW_UNINSTALL="postgis gdal" + - osx_image: xcode12 install: - brew list - brew install python # gdal breaks pip3 update - - brew uninstall postgis gdal + - [ -n "$BREW_UNINSTALL" ] && brew uninstall $BREW_UNINSTALL - pip3 install ansible script: - ansible-playbook macdev.yml --syntax-check - - > - cp host_vars/localhost-example.yml host_vars/localhost.yml; - sed -i '' -e 's/role_ssh: yes/role_ssh: no/' host_vars/localhost.yml + - cp host_vars/localhost-example.yml host_vars/localhost.yml # run the playbook - ansible-playbook macdev.yml # run again -> expect no change diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 0dafa99..0e328b6 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -3,8 +3,8 @@ # - name: Check pip version - name: List outdated packages shell: pip3 list --outdated --format=freeze - register: pip3-outdated -- debug: var=pip3-outdated.stdout_lines + register: pip3_outdated +- debug: var=pip3_outdated.stdout_lines - name: Upgrade packages shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip3_omit_upgrade}}\)' | xargs -n1 pip3 install -U diff --git a/roles/ssh/tasks/main.yml b/roles/ssh/tasks/main.yml index 76a12e4..54e5fb5 100644 --- a/roles/ssh/tasks/main.yml +++ b/roles/ssh/tasks/main.yml @@ -5,14 +5,14 @@ - name: Check for SSH private key stat: path=$HOME/.ssh/id_rsa - register: ssh-private + register: ssh_private - name: SSH private key permissions file: path=$HOME/.ssh/id_rsa owner={{ ansible_user_id }} group={{ user_group }} mode=0600 - when: ssh-private.stat.exists + when: ssh_private.stat.exists - name: Check for SSH public key stat: path=$HOME/.ssh/id_rsa.pub - register: ssh-public + register: ssh_public - name: SSH public key permission file: path=$HOME/.ssh/id_rsa.pub owner={{ ansible_user_id }} group={{ user_group }} mode=0644 - when: ssh-public.stat.exists + when: ssh_public.stat.exists From 10483c90165f5ad9a5ce02ee7ecbe39eff2f760b Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 15:00:34 +0200 Subject: [PATCH 11/51] fix: configurable uninstall of brew packages (per build) --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d05088..82ce223 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,15 @@ os: osx jobs: include: - - osx_image: xcode10.1 + - name: "macOS 10.13.6" + osx_image: xcode10.1 # swiftlint requires xcode10.2 env: BREW_UNINSTALL="postgis gdal swiftlint" - - osx_image: xcode11.3 + - name: "macOS 10.14.6" + osx_image: xcode11.3 env: BREW_UNINSTALL="postgis gdal" - - osx_image: xcode12 + - name: "macOS 10.15.6" + osx_image: xcode12 install: - brew list From 6275bf543db18108755918e9ddc67a9ab576ee62 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 15:12:24 +0200 Subject: [PATCH 12/51] fix: configurable uninstall of brew packages (per build) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 82ce223..bf1d0d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ os: osx +osx_image: xcode12 jobs: include: From 2be8e34d6621a11198a0edd8a76e9309f59cb76e Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 16:00:37 +0200 Subject: [PATCH 13/51] fix: configurable uninstall of brew packages (per build) --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf1d0d6..edad004 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ os: osx -osx_image: xcode12 jobs: include: @@ -17,7 +16,7 @@ install: - brew list - brew install python # gdal breaks pip3 update - - [ -n "$BREW_UNINSTALL" ] && brew uninstall $BREW_UNINSTALL + - test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL - pip3 install ansible script: From 43483958a3ce663b379a3eee90b9e30efe9e8d63 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 16:07:31 +0200 Subject: [PATCH 14/51] fix: configurable uninstall of brew packages (per build) --- .travis.yml | 2 +- roles/pip/tasks/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index edad004..9c4aa19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - brew list - brew install python # gdal breaks pip3 update - - test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL + - test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL || exit 0 - pip3 install ansible script: diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 0e328b6..19b46f6 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -7,7 +7,7 @@ - debug: var=pip3_outdated.stdout_lines - name: Upgrade packages - shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip3_omit_upgrade}}\)' | xargs -n1 pip3 install -U + shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip_omit_upgrade}}\)' | xargs -n1 pip3 install -U args: executable: /bin/bash register: pip_upgrade From 663851012f65230480e3dc96c9e442adf2a808a9 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 16:17:04 +0200 Subject: [PATCH 15/51] fix: exit subshell --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9c4aa19..f8270e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - brew list - brew install python # gdal breaks pip3 update - - test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL || exit 0 + - (test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL || exit 0) - pip3 install ansible script: From 1ad1877a93f71202d78999936b3fff71fc4ca653 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 17:03:02 +0200 Subject: [PATCH 16/51] fix: use homebrew[_cask] --- roles/brew/tasks/main.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 8365bbd..df0c42d 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -19,28 +19,27 @@ when: brew_multiuser|bool == true - name: Upgrade homebrew - shell: brew upgrade + homebrew: + update_homebrew: yes + upgrade_all: yes register: brew_upgrade - changed_when: brew_upgrade.stdout|length > 1 and not brew_upgrade.stdout|regex_search("No changes to formulae.") +# changed_when: brew_upgrade.stdout|length > 1 and not brew_upgrade.stdout|regex_search("No changes to formulae.") - name: Install brew packages - shell: brew install {{ item.name }} - args: - executable: /bin/bash - creates: "{{ item.path }}" + homebrew: + name: {{ item.name }} with_items: "{{ brew_packages }}" when: brew_packages[0] is defined - name: Upgrade homebrew casks - shell: brew cask upgrade + homebrew_cask: + upgrade_all: true register: cask_upgrade - changed_when: cask_upgrade.stdout_lines|length > 1 +# changed_when: cask_upgrade.stdout_lines|length > 1 - name: Install brew cask packages - shell: brew cask install {{ item.name }} - args: - executable: /bin/bash - creates: "{{ item.path }}" + homebrew_cask: + name: {{ item.name }} with_items: "{{ brew_cask_packages }}" when: brew_cask_packages[0] is defined From 80bd6c5c65c4c0ea493979a3d6decfb679f6ac76 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 17:08:28 +0200 Subject: [PATCH 17/51] fix: use pip --- .travis.yml | 2 +- roles/brew/tasks/main.yml | 4 ++-- roles/pip/tasks/main.yml | 16 +++++----------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index f8270e4..f20e0d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,6 @@ script: # run again -> expect no change - > ansible-playbook macdev.yml - | grep -e 'changed=0.*failed=0' -e '^changed' + | grep -A2 -e 'changed=0.*failed=0' -e '^changed' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index df0c42d..1c34e05 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -27,7 +27,7 @@ - name: Install brew packages homebrew: - name: {{ item.name }} + name: "{{ item.name }}" with_items: "{{ brew_packages }}" when: brew_packages[0] is defined @@ -39,7 +39,7 @@ - name: Install brew cask packages homebrew_cask: - name: {{ item.name }} + name: "{{ item.name }}" with_items: "{{ brew_cask_packages }}" when: brew_cask_packages[0] is defined diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 19b46f6..3bf617f 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -1,11 +1,5 @@ --- -# - name: Check pip version -- name: List outdated packages - shell: pip3 list --outdated --format=freeze - register: pip3_outdated -- debug: var=pip3_outdated.stdout_lines - - name: Upgrade packages shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip_omit_upgrade}}\)' | xargs -n1 pip3 install -U args: @@ -13,11 +7,11 @@ register: pip_upgrade failed_when: pip_upgrade.rc == 1 changed_when: pip_upgrade.stdout_lines|length > 0 +- debug: var=pip_upgrade.stdout_lines + when: pip_upgrade|changed - name: Install packages - shell: pip3 install {{ item.name }} - args: - executable: /bin/bash - creates: "{{ item.path }}" + pip: + name: "{{ item.name }}" + executable: pip3 with_items: "{{ pip_packages }}" - From 76b3639279226f5e85be0517ee6661ecbee833fb Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 17:20:25 +0200 Subject: [PATCH 18/51] fix: use pip --- roles/pip/tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 3bf617f..c09bf65 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -8,10 +8,11 @@ failed_when: pip_upgrade.rc == 1 changed_when: pip_upgrade.stdout_lines|length > 0 - debug: var=pip_upgrade.stdout_lines - when: pip_upgrade|changed + when: pip_upgrade is changed - name: Install packages pip: name: "{{ item.name }}" + state: latest executable: pip3 with_items: "{{ pip_packages }}" From f90840d36a2f58a4660df6f52ed3b5aad67d46f0 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 18:00:03 +0200 Subject: [PATCH 19/51] fix: use pip --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f20e0d7..9978996 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,20 +2,19 @@ os: osx jobs: include: - - name: "macOS 10.13.6" + - name: "XCode 10.1 macOS 10.13.6" osx_image: xcode10.1 # swiftlint requires xcode10.2 env: BREW_UNINSTALL="postgis gdal swiftlint" - - name: "macOS 10.14.6" + - name: "XCode 11.3 macOS 10.14.6" osx_image: xcode11.3 env: BREW_UNINSTALL="postgis gdal" - - name: "macOS 10.15.6" + - name: "XCode 12 macOS 10.15.6" osx_image: xcode12 install: - brew list - brew install python - # gdal breaks pip3 update - (test -n "$BREW_UNINSTALL" && brew uninstall $BREW_UNINSTALL || exit 0) - pip3 install ansible From 1e07ba3c945a5220445808af5c3a91e2662ceb97 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 18:06:25 +0200 Subject: [PATCH 20/51] fix: split homebrew update & upgrade --- roles/brew/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 1c34e05..f996d85 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -18,24 +18,24 @@ changed_when: false when: brew_multiuser|bool == true -- name: Upgrade homebrew +- name: Update homebrew homebrew: update_homebrew: yes + +- name: Upgrade homebrew packages + homebrew: upgrade_all: yes - register: brew_upgrade -# changed_when: brew_upgrade.stdout|length > 1 and not brew_upgrade.stdout|regex_search("No changes to formulae.") - name: Install brew packages homebrew: name: "{{ item.name }}" + state: latest with_items: "{{ brew_packages }}" when: brew_packages[0] is defined - name: Upgrade homebrew casks homebrew_cask: - upgrade_all: true - register: cask_upgrade -# changed_when: cask_upgrade.stdout_lines|length > 1 + upgrade_all: yes - name: Install brew cask packages homebrew_cask: From 5f4ba4441f96893606a4115793ae23957442793e Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 20:30:15 +0200 Subject: [PATCH 21/51] fix: optional skip brew upgrade --- .travis.yml | 4 ++-- roles/brew/tasks/main.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9978996..039349b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ script: - ansible-playbook macdev.yml --syntax-check - cp host_vars/localhost-example.yml host_vars/localhost.yml # run the playbook - - ansible-playbook macdev.yml + - ansible-playbook macdev.yml -e brew_skip_upgrade=true # run again -> expect no change - > - ansible-playbook macdev.yml + ansible-playbook macdev.yml -e brew_skip_upgrade=true | grep -A2 -e 'changed=0.*failed=0' -e '^changed' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index f996d85..64f062f 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -25,6 +25,7 @@ - name: Upgrade homebrew packages homebrew: upgrade_all: yes + when: not brew_skip_upgrade|default(false) - name: Install brew packages homebrew: @@ -36,6 +37,7 @@ - name: Upgrade homebrew casks homebrew_cask: upgrade_all: yes + when: not brew_cask_skip_upgrade|default(false) - name: Install brew cask packages homebrew_cask: From bad17bf22faa75070a4aa33b54f9f4b3d3a7841d Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 20:54:53 +0200 Subject: [PATCH 22/51] fix: upgrade python and ansible in one command --- roles/brew/tasks/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 64f062f..9c19055 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -27,7 +27,11 @@ upgrade_all: yes when: not brew_skip_upgrade|default(false) -- name: Install brew packages +- name: Install/Update python + ansible + shell: pip3 install -U python; pip3 install -U ansible + when: "python" in brew_packages|map(attribute="name")|flatten + +- name: Install/Update brew packages homebrew: name: "{{ item.name }}" state: latest From 2a69ee9d80cdc5c6bc4f90d1d43a2c4692ceb751 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 21:03:18 +0200 Subject: [PATCH 23/51] fix: upgrade python and ansible in one command --- roles/brew/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 9c19055..4ca13f9 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -29,7 +29,7 @@ - name: Install/Update python + ansible shell: pip3 install -U python; pip3 install -U ansible - when: "python" in brew_packages|map(attribute="name")|flatten + when: '"python" in brew_packages|map(attribute="name")|flatten' - name: Install/Update brew packages homebrew: From 7a222bd2ff7c15768ee6a8d11e64c435095ab714 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 21:22:09 +0200 Subject: [PATCH 24/51] fix: skip packages from examples --- host_vars/localhost-example.yml | 6 +++--- roles/brew/tasks/main.yml | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/host_vars/localhost-example.yml b/host_vars/localhost-example.yml index 275de3d..fee8571 100644 --- a/host_vars/localhost-example.yml +++ b/host_vars/localhost-example.yml @@ -37,11 +37,11 @@ brew_packages: - { name: kubernetes-cli, path: /usr/local/bin/kubectl } - { name: kubectx, path: /usr/local/bin/kubectx } - { name: hub, path: /usr/local/bin/hub } - - { name: go, path: /usr/local/bin/go } + #- { name: go, path: /usr/local/bin/go } #- { name: go@1.12, path: /usr/local/Cellar/go@1.12 } - { name: pinentry-mac, path: /usr/local/bin/pinentry-mac } - - { name: node, path: /usr/local/bin/node } - - { name: telegraf, path: /usr/local/bin/telegraf } + #- { name: node, path: /usr/local/bin/node } + #- { name: telegraf, path: /usr/local/bin/telegraf } - { name: mtr, path: /usr/local/sbin/mtr } - { name: smartmontools, path: /usr/local/bin/smartctl } #- { name: glances, path: /usr/local/bin/glances } diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 4ca13f9..2e1f0d8 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -30,6 +30,8 @@ - name: Install/Update python + ansible shell: pip3 install -U python; pip3 install -U ansible when: '"python" in brew_packages|map(attribute="name")|flatten' + register: python_update +- debug: var=python_update - name: Install/Update brew packages homebrew: From 6525568d24fb758225d24fc1747cbc3a66025f8e Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 21:49:14 +0200 Subject: [PATCH 25/51] fix: changed_when fix: use lists instead of loops --- .travis.yml | 2 +- roles/brew/tasks/main.yml | 10 +++++----- roles/pip/tasks/main.yml | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 039349b..5ccd26b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,6 @@ script: # run again -> expect no change - > ansible-playbook macdev.yml -e brew_skip_upgrade=true - | grep -A2 -e 'changed=0.*failed=0' -e '^changed' + | grep -B1 -e 'changed=0.*failed=0' -e '^changed' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 2e1f0d8..74d222a 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -28,16 +28,17 @@ when: not brew_skip_upgrade|default(false) - name: Install/Update python + ansible - shell: pip3 install -U python; pip3 install -U ansible + shell: brew install python; pip3 install -U ansible when: '"python" in brew_packages|map(attribute="name")|flatten' register: python_update + failed_when: python_update.rc != 0 + changed_when: 'not python_update.stdout|contains("already up-to-date: ansible")' - debug: var=python_update - name: Install/Update brew packages homebrew: - name: "{{ item.name }}" + name: "{{ brew_packages|map(attribute='name')|flatten }}" state: latest - with_items: "{{ brew_packages }}" when: brew_packages[0] is defined - name: Upgrade homebrew casks @@ -47,7 +48,6 @@ - name: Install brew cask packages homebrew_cask: - name: "{{ item.name }}" - with_items: "{{ brew_cask_packages }}" + name: "{{ brew_cask_packages|map(attribute='name')|flatten }}" when: brew_cask_packages[0] is defined diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index c09bf65..978f6df 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -5,14 +5,13 @@ args: executable: /bin/bash register: pip_upgrade - failed_when: pip_upgrade.rc == 1 - changed_when: pip_upgrade.stdout_lines|length > 0 + failed_when: pip_upgrade.rc != 0 + changed_when: pip_upgrade.stdout|contains("Successfully installed") - debug: var=pip_upgrade.stdout_lines when: pip_upgrade is changed - name: Install packages pip: - name: "{{ item.name }}" + name: "{{ pip_packages|map(attribute='name')|flatten }}" state: latest executable: pip3 - with_items: "{{ pip_packages }}" From c5bf9be422d985cf4e60a58b11232910739c07d7 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 22:49:00 +0200 Subject: [PATCH 26/51] fix: changed_when --- roles/brew/tasks/main.yml | 2 +- roles/pip/tasks/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 74d222a..160f5cb 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -32,7 +32,7 @@ when: '"python" in brew_packages|map(attribute="name")|flatten' register: python_update failed_when: python_update.rc != 0 - changed_when: 'not python_update.stdout|contains("already up-to-date: ansible")' + changed_when: 'not python_update.stdout is search("already up-to-date: ansible")' - debug: var=python_update - name: Install/Update brew packages diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 978f6df..848bc78 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -6,7 +6,7 @@ executable: /bin/bash register: pip_upgrade failed_when: pip_upgrade.rc != 0 - changed_when: pip_upgrade.stdout|contains("Successfully installed") + changed_when: pip_upgrade.stdout is search("Successfully installed") - debug: var=pip_upgrade.stdout_lines when: pip_upgrade is changed From f1aa83dee039621cb0cad00715a3c57e6d3eb184 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 23:15:59 +0200 Subject: [PATCH 27/51] fix: timeout on brew install --- roles/brew/tasks/main.yml | 7 ++++--- roles/pip/tasks/main.yml | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 160f5cb..6f5db4f 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -33,12 +33,12 @@ register: python_update failed_when: python_update.rc != 0 changed_when: 'not python_update.stdout is search("already up-to-date: ansible")' -- debug: var=python_update - name: Install/Update brew packages homebrew: - name: "{{ brew_packages|map(attribute='name')|flatten }}" + name: "{{ item }}" state: latest + with_items: "{{ brew_packages|map(attribute='name')|flatten }}" when: brew_packages[0] is defined - name: Upgrade homebrew casks @@ -48,6 +48,7 @@ - name: Install brew cask packages homebrew_cask: - name: "{{ brew_cask_packages|map(attribute='name')|flatten }}" + name: "{{ item }}" + with_items: "{{ brew_cask_packages|map(attribute='name')|flatten }}" when: brew_cask_packages[0] is defined diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 848bc78..95d220d 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -7,8 +7,6 @@ register: pip_upgrade failed_when: pip_upgrade.rc != 0 changed_when: pip_upgrade.stdout is search("Successfully installed") -- debug: var=pip_upgrade.stdout_lines - when: pip_upgrade is changed - name: Install packages pip: From 8ff9b9320a4c07997e4e14ead8d89d00e7827915 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 23:38:41 +0200 Subject: [PATCH 28/51] fix: debug 'changed' reason --- .travis.yml | 2 +- roles/brew/tasks/main.yml | 3 +++ roles/pip/tasks/main.yml | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5ccd26b..74a6c2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,6 @@ script: # run again -> expect no change - > ansible-playbook macdev.yml -e brew_skip_upgrade=true - | grep -B1 -e 'changed=0.*failed=0' -e '^changed' + | grep -B1 -A30 -e 'changed=0.*failed=0' -e '^changed' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) \ No newline at end of file diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 6f5db4f..d1b1e2f 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -45,6 +45,9 @@ homebrew_cask: upgrade_all: yes when: not brew_cask_skip_upgrade|default(false) + register: cask_upgrade +- debug: var=cask_upgrade.stdout_lines + when: cask_upgrade is changed - name: Install brew cask packages homebrew_cask: diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 95d220d..162304d 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -1,5 +1,11 @@ --- +- name: Update pip3 + pip: + name: pip + state: latest + executable: pip3 + - name: Upgrade packages shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip_omit_upgrade}}\)' | xargs -n1 pip3 install -U args: @@ -7,9 +13,14 @@ register: pip_upgrade failed_when: pip_upgrade.rc != 0 changed_when: pip_upgrade.stdout is search("Successfully installed") +- debug: var=pip_upgrade.stdout_lines + when: pip_upgrade is changed - name: Install packages pip: name: "{{ pip_packages|map(attribute='name')|flatten }}" state: latest executable: pip3 + register: pip_install +- debug: var=pip_install + when: pip_install is changed From 836ce698f71c0375f991840972a7c6b035438798 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 20 Sep 2020 23:58:57 +0200 Subject: [PATCH 29/51] fix: debug 'changed' reason --- roles/brew/tasks/main.yml | 2 +- roles/pip/tasks/main.yml | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index d1b1e2f..11860d9 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -46,7 +46,7 @@ upgrade_all: yes when: not brew_cask_skip_upgrade|default(false) register: cask_upgrade -- debug: var=cask_upgrade.stdout_lines +- debug: var=cask_upgrade when: cask_upgrade is changed - name: Install brew cask packages diff --git a/roles/pip/tasks/main.yml b/roles/pip/tasks/main.yml index 162304d..22e5a06 100644 --- a/roles/pip/tasks/main.yml +++ b/roles/pip/tasks/main.yml @@ -6,8 +6,17 @@ state: latest executable: pip3 +- name: Install packages + pip: + name: "{{ pip_packages|map(attribute='name')|flatten }}" + state: latest + executable: pip3 + register: pip_install +- debug: var=pip_install + when: pip_install is changed + - name: Upgrade packages - shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{pip_omit_upgrade}}\)' | xargs -n1 pip3 install -U + shell: pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | grep -v '\({{ pip_omit_upgrade|default("none") }}\)' | xargs -n1 pip3 install -U args: executable: /bin/bash register: pip_upgrade @@ -16,11 +25,3 @@ - debug: var=pip_upgrade.stdout_lines when: pip_upgrade is changed -- name: Install packages - pip: - name: "{{ pip_packages|map(attribute='name')|flatten }}" - state: latest - executable: pip3 - register: pip_install -- debug: var=pip_install - when: pip_install is changed From 22a3bc5403fe34b1c0536c37d987eed4f43228c9 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 21 Sep 2020 18:43:52 +0200 Subject: [PATCH 30/51] fix: cask update never changed fix: install fewer packages by default --- host_vars/localhost-example.yml | 14 +++++++------- roles/brew/tasks/main.yml | 8 +++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/host_vars/localhost-example.yml b/host_vars/localhost-example.yml index fee8571..9f1785f 100644 --- a/host_vars/localhost-example.yml +++ b/host_vars/localhost-example.yml @@ -34,9 +34,9 @@ brew_packages: - { name: jq, path: /usr/local/bin/jq } - { name: gnupg, path: /usr/local/bin/gpg } #- { name: bash-completion, path: /usr/local/etc/profile.d/bash_completion.sh } - - { name: kubernetes-cli, path: /usr/local/bin/kubectl } - - { name: kubectx, path: /usr/local/bin/kubectx } - - { name: hub, path: /usr/local/bin/hub } + #- { name: kubernetes-cli, path: /usr/local/bin/kubectl } + #- { name: kubectx, path: /usr/local/bin/kubectx } + #- { name: hub, path: /usr/local/bin/hub } #- { name: go, path: /usr/local/bin/go } #- { name: go@1.12, path: /usr/local/Cellar/go@1.12 } - { name: pinentry-mac, path: /usr/local/bin/pinentry-mac } @@ -46,9 +46,9 @@ brew_packages: - { name: smartmontools, path: /usr/local/bin/smartctl } #- { name: glances, path: /usr/local/bin/glances } #- { name: ask-cli, path: /usr/local/bin/ask } - - { name: zsh, path: /usr/local/bin/zsh } - - { name: zsh-syntax-highlighting, path: /usr/local/share/zsh-syntax-highlighting } - - { name: zsh-autosuggestions, path: /usr/local/share/zsh-autosuggestions } + #- { name: zsh, path: /usr/local/bin/zsh } + #- { name: zsh-syntax-highlighting, path: /usr/local/share/zsh-syntax-highlighting } + #- { name: zsh-autosuggestions, path: /usr/local/share/zsh-autosuggestions } brew_cask_packages: #- { name: docker, path: /Applications/Docker.app } @@ -72,7 +72,7 @@ brew_cask_packages: pip_packages: - { name: ansible, path: /usr/local/bin/ansible } - - { name: awscli, path: /usr/local/bin/aws } + #- { name: awscli, path: /usr/local/bin/aws } # mercurial is part of distutils pip_omit_upgrade: "mercurial" diff --git a/roles/brew/tasks/main.yml b/roles/brew/tasks/main.yml index 11860d9..779099b 100644 --- a/roles/brew/tasks/main.yml +++ b/roles/brew/tasks/main.yml @@ -45,9 +45,11 @@ homebrew_cask: upgrade_all: yes when: not brew_cask_skip_upgrade|default(false) - register: cask_upgrade -- debug: var=cask_upgrade - when: cask_upgrade is changed + # TODO: remove this when the module properly reports changes + changed_when: false +# register: cask_upgrade +#- debug: var=cask_upgrade +# when: cask_upgrade is changed - name: Install brew cask packages homebrew_cask: From 49e6c314138c53fd23c66e9e424281bae28c3a45 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 17 Jan 2021 14:08:26 +0100 Subject: [PATCH 31/51] Add spotify, sweethome3d, ... --- host_vars/localhost-standardapps.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/host_vars/localhost-standardapps.yml b/host_vars/localhost-standardapps.yml index 52f6d3f..6fd6108 100644 --- a/host_vars/localhost-standardapps.yml +++ b/host_vars/localhost-standardapps.yml @@ -75,6 +75,10 @@ brew_cask_packages: - { name: discord, path: "/Applications/Discord.app" } - { name: google-backup-and-sync, path: "/Applications/Backup and Sync.app" } - { name: vlc, path: "/Applications/VLC.app" } + #- { name: iina, path: "/Applications/Iina.app" } + #- { name: background-music, path: "/Applications/Background Music.app" } + - { name: spotify, path: "/Applications/Spotify.app" } + #- { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } pip_packages: - { name: ansible, path: /usr/local/bin/ansible } From 9587c090a527dde2c514256c83b01bcc2390d5a9 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 17 Jan 2021 14:12:25 +0100 Subject: [PATCH 32/51] run brew upgrade manually if it fails --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9c73995..e7e0b8e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ You want to install a new package? Edit your `host_vars/localhost.yml`, then sim ## troubleshooting * if you get this (after updating brew): `/usr/local/bin/ansible-playbook: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory` * then run `pip3 install -U ansible` and try again +* brew upgrade fails: + * if brew upgrade sometimes requires user interaction or fails, simply run it manually once: `brew upgrade` # setup ENV for mac and ansible: see https://gist.github.com/DrPsychick/847ea32c876fda2337e79096a8a23176 From 07d2db851f3a65e56e680fed1ae1df33e7f72c24 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 6 Feb 2021 17:27:49 +0100 Subject: [PATCH 33/51] feat: support bash & zsh feat: source files/templates in profile (login shell) or rc file (interactive shell) fix: support new brew location (/opt) fix: add defaults for variables --- host_vars/localhost-standardapps.yml | 58 ++++++++--------- macdev.yml | 4 +- roles/env/tasks/main.yml | 96 ++++++++++++++++++++++------ 3 files changed, 102 insertions(+), 56 deletions(-) diff --git a/host_vars/localhost-standardapps.yml b/host_vars/localhost-standardapps.yml index 6fd6108..59d67fd 100644 --- a/host_vars/localhost-standardapps.yml +++ b/host_vars/localhost-standardapps.yml @@ -4,12 +4,6 @@ # ### - -# defaults -user_group: admin -# will set ACL and chgrp for /usr/local/Homebrew|Caskroom|Celler|bin -brew_multiuser: no - # roles role_ssh: no role_pip: yes @@ -21,37 +15,37 @@ role_app: no # shell: source file in .profile # files you want to copy to the target -files: - #- { name: "gitconfig-example", path: "$HOME/.gitconfig-example", overwrite: true, shell: false } +#files: + #- { name: "gitconfig-example", path: "$HOME/.gitconfig-example", overwrite: true } # templates you want to copy to the target -templates: - #- { name: "bashrc-example", path: "$HOME/.bashrc-example", overwrite: true, shell: true } - #- { name: "bash_aliases-example", path: "$HOME/.bash_aliases-example", overwrite: true, shell: true } +#templates: + #- { name: "bashrc-example", path: "$HOME/.bashrc-example", overwrite: true } + #- { name: "bash_aliases-example", path: "$HOME/.bash_aliases-example", overwrite: true, source: "interactive" } # instead of copying a file or template, you can define aliases one by one shell_aliases: - { name: "updatemac", cmd: "(cd {{playbook_dir}}; ansible-playbook macdev.yml)" } brew_packages: - - { name: python, path: /usr/local/bin/python3 } - #- { name: pwgen, path: /usr/local/bin/pwgen } - #- { name: jq, path: /usr/local/bin/jq } - - { name: gnupg, path: /usr/local/bin/gpg } + - { name: python, path: "{{ brew_bin }}/python3" } + #- { name: pwgen, path: "{{ brew_bin }}/pwgen" } + #- { name: jq, path: "{{ brew_bin }}/jq" } + - { name: gnupg, path: "{{ brew_bin }}/gpg" } #- { name: bash-completion, path: /usr/local/etc/profile.d/bash_completion.sh } - #- { name: kubernetes-cli, path: /usr/local/bin/kubectl } - #- { name: kubectx, path: /usr/local/bin/kubectx } - #- { name: hub, path: /usr/local/bin/hub } - #- { name: go, path: /usr/local/bin/go } + #- { name: kubernetes-cli, path: "{{ brew_bin }}/kubectl" } + #- { name: kubectx, path: "{{ brew_bin }}/kubectx" } + #- { name: hub, path: "{{ brew_bin }}/hub" } + #- { name: go, path: "{{ brew_bin }}/go" } #- { name: go@1.12, path: /usr/local/Cellar/go@1.12 } - #- { name: pinentry-mac, path: /usr/local/bin/pinentry-mac } - #- { name: node, path: /usr/local/bin/node } - #- { name: telegraf, path: /usr/local/bin/telegraf } - #- { name: mtr, path: /usr/local/sbin/mtr } - - { name: smartmontools, path: /usr/local/bin/smartctl } - #- { name: glances, path: /usr/local/bin/glances } - #- { name: ask-cli, path: /usr/local/bin/ask } - #- { name: zsh, path: /usr/local/bin/zsh } + #- { name: pinentry-mac, path: "{{ brew_bin }}/pinentry-mac" } + #- { name: node, path: "{{ brew_bin }}/node" } + #- { name: telegraf, path: "{{ brew_bin }}/telegraf" } + #- { name: mtr, path: "{{ brew_sbin }}/mtr" } + - { name: smartmontools, path: "{{ brew_bin }}/smartctl" } + #- { name: glances, path: "{{ brew_bin }}/glances" } + #- { name: ask-cli, path: "{{ brew_bin }}/ask" } + #- { name: zsh, path: "{{ brew_bin }}/zsh" } #- { name: zsh-syntax-highlighting, path: /usr/local/share/zsh-syntax-highlighting } #- { name: zsh-autosuggestions, path: /usr/local/share/zsh-autosuggestions } @@ -59,12 +53,12 @@ brew_cask_packages: #- { name: docker, path: "/Applications/Docker.app" } - { name: iterm2, path: "/Applications/iTerm.app" } - { name: google-chrome, path: "/Applications/Google Chrome.app" } - - { name: atom, path: "/Applications/Atom.app" } - #- { name: postman, path: "/Applications/Postman.app" } +# - { name: atom, path: "/Applications/Atom.app" } +# - { name: postman, path: "/Applications/Postman.app" } - { name: slack, path: "/Applications/Slack.app" } - { name: macpass, path: "/Applications/MacPass.app" } - { name: openoffice, path: "/Applications/OpenOffice.app" } - - { name: gimp, path: "/Applications/GIMP-2.10.app" } +# - { name: gimp, path: "/Applications/GIMP-2.10.app" } #- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } #- { name: spectacle, path: "/Applications/Spectacle.app" } - { name: drawio, path: "/Applications/draw.io.app" } @@ -81,8 +75,8 @@ brew_cask_packages: #- { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } pip_packages: - - { name: ansible, path: /usr/local/bin/ansible } - #- { name: awscli, path: /usr/local/bin/aws } + - { name: ansible, path: "{{ pip_bin }}/ansible" } + #- { name: awscli, path: "{{ pip_bin }}/aws" } # supports .zip and .dmg app_packages: diff --git a/macdev.yml b/macdev.yml index cfed024..181b673 100644 --- a/macdev.yml +++ b/macdev.yml @@ -1,8 +1,6 @@ --- -- name: +- name: Simple macOS setup hosts: localhost - environment: - BASH_ENV: "~/.profile" # required to load the local environment (PATH etc.) roles: - { role: env } - { role: ssh, when: role_ssh|bool } diff --git a/roles/env/tasks/main.yml b/roles/env/tasks/main.yml index ec2fcb3..ef9ab43 100644 --- a/roles/env/tasks/main.yml +++ b/roles/env/tasks/main.yml @@ -1,60 +1,114 @@ --- -- name: Load system paths from user profile +# source=login: load in profile/zprofile (/etc, then $HOME) +# => should set environment also for script sessions etc. +# source=interactive: load in .bashrc/.zshrc (/etc, then $HOME) +# => should set environment for interactive use (terminal, SSH) + +# determine profile file name +# see https://superuser.com/questions/187639/zsh-not-hitting-profile#:~:text=profile%20(or%20~%2F.,zshrc%20. +# .profile = sh/bash +# .zprofile = zsh +# Options: +# use .profile for backwards compatibility and load it in zsh: "zsh_load_sh_profile: true" + +- name: Determine shell + shell: echo $SHELL + register: local_shell + changed_when: false + +- name: Set shell + set_fact: + shell: '{{ local_shell.stdout }}' + zsh_path: '{{ zsh_path|default("/bin/zsh") }}' + +- name: Set variables shell_profile/shell_rc and defaults + set_fact: + user_group: '{{ user_group|default("admin") }}' + shell_aliases: '{{ shell_aliases|default([]) }}' + files: '{{ files|default([]) }}' + templates: '{{ templates|default([]) }}' + zsh_load_sh_profile: '{{ zsh_load_sh_profile|default(false) }}' + shell_profile: '{{ ".zprofile" if shell == zsh_path else ".profile" }}' + shell_rc: '{{ ".zshrc" if shell == zsh_path else ".bashrc" }}' + +- name: Print environment + debug: + msg: "profile '{{ shell_profile }}', rc file '{{ shell_rc }}'" + +- name: Load shell profile in zsh lineinfile: - dest: $HOME/.profile - regexp: "^[#]?source /etc/profile" - line: "source /etc/profile" + dest: '{{ "$HOME/" + shell_profile }}' + regexp: "^emulate sh.*\\.profile.*" + line: "emulate sh -c '. ~/.profile'" create: yes - #remote_user: "{{ ansible_user_id }}" + when: zsh_load_sh_profile -- name: Add aliases to .profile +- name: "Add aliases to {{ shell_profile }}" lineinfile: - dest: $HOME/.profile + dest: '{{ "$HOME/" + shell_profile }}' regexp: "^[#]?alias {{ item.name }}=.*" line: "alias {{ item.name }}='{{ item.cmd }}'" + create: yes with_items: "{{ shell_aliases }}" - when: shell_aliases[0] is defined # must be a non-empty list + when: shell_aliases|length > 0 +# files +# fails if a file exists that should not be overwritten - name: Check for existing files without overwrite stat: path={{ item.path }} with_items: "{{ files }}" - when: files[0] is defined and item.overwrite != true + when: files|length > 0 and item.overwrite != true register: file failed_when: file.stat.exists - name: Copy files copy: src={{ item.name }} dest={{ item.path }} owner={{ ansible_user_id }} group={{ user_group }} mode=0755 with_items: "{{ files }}" - when: files[0] is defined + when: files|length > 0 + +- name: "Load files in shell environment ({{shell_profile}})" + lineinfile: + dest: '{{ "$HOME/" + shell_profile }}' + regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" + line: "source {{ item.path }}" + with_items: "{{ files }}" + when: files|length > 0 and item.source|default("") == "login" +- name: "Load files in shell environment ({{shell_rc}})" + lineinfile: + dest: '{{ "$HOME/" + shell_rc }}' + regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" + line: "source {{ item.path }}" + with_items: "{{ files }}" + when: files|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") + +# templates # fails if a file exists that should not be overwritten - name: Check for existing template files without overwrite stat: path={{ item.path }} with_items: "{{ templates }}" - when: templates[0] is defined and item.overwrite != true + when: templates|length > 0 and item.overwrite != true register: template failed_when: template.stat.exists - name: Copy templates template: src={{ item.name }} dest={{ item.path }} owner={{ ansible_user_id }} group={{ user_group }} mode=0755 with_items: "{{ templates }}" - when: templates[0] is defined + when: templates|length > 0 -- name: Load files in shell environment (.profile) +- name: "Load templates in shell environment ({{shell_profile}})" lineinfile: - dest: $HOME/.profile + dest: '{{ "$HOME/" + shell_profile }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" - with_items: "{{ files }}" - when: files[0] is defined and item.shell + with_items: "{{ templates }}" + when: templates|length > 0 and item.source|default("") == "login" -- name: Load templates in shell environment (.profile) +- name: "Load templates in shell environment ({{shell_rc}})" lineinfile: - dest: $HOME/.profile + dest: '{{ "$HOME/" + shell_rc }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" with_items: "{{ templates }}" - when: templates[0] is defined and item.shell - - + when: templates|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") From e0d6b6bf323fcba993f54f4676b680b395f46d08 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 6 Feb 2021 17:52:40 +0100 Subject: [PATCH 34/51] create if files missing --- roles/env/tasks/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/env/tasks/main.yml b/roles/env/tasks/main.yml index ef9ab43..a7d5910 100644 --- a/roles/env/tasks/main.yml +++ b/roles/env/tasks/main.yml @@ -72,6 +72,7 @@ dest: '{{ "$HOME/" + shell_profile }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" + create: yes with_items: "{{ files }}" when: files|length > 0 and item.source|default("") == "login" @@ -80,6 +81,7 @@ dest: '{{ "$HOME/" + shell_rc }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" + create: yes with_items: "{{ files }}" when: files|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") @@ -102,6 +104,7 @@ dest: '{{ "$HOME/" + shell_profile }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" + create: yes with_items: "{{ templates }}" when: templates|length > 0 and item.source|default("") == "login" @@ -110,5 +113,6 @@ dest: '{{ "$HOME/" + shell_rc }}' regexp: "^[#]?source {{ item.path|replace('$', '\\$') }}" line: "source {{ item.path }}" + create: yes with_items: "{{ templates }}" when: templates|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") From 38858e792cbd0db3d3bc7693036e7f5d55f8f76e Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 24 Apr 2021 23:47:59 +0200 Subject: [PATCH 35/51] feat: add functions-example fix: zoomus -> zoom fix: brew upgrade - ignore failure (pinned versions) --- host_vars/localhost-example.yml | 2 +- host_vars/localhost-standardapps.yml | 10 +++++----- templates/functions-example | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 templates/functions-example diff --git a/host_vars/localhost-example.yml b/host_vars/localhost-example.yml index 9f1785f..f0bf5d1 100644 --- a/host_vars/localhost-example.yml +++ b/host_vars/localhost-example.yml @@ -66,7 +66,7 @@ brew_cask_packages: #- { name: krita, path: "/Applications/krita.app" } #- { name: obs, path: "/Applications/OBS.app" } #- { name: moonlight, path: "/Applications/Moonlight.app" } - #- { name: zoomus, path: "/Applications/zoom.us.app" } + #- { name: zoom, path: "/Applications/zoom.us.app" } #- { name: discord, path: "/Applications/Discord.app" } #- { name: google-backup-and-sync, path: "/Applications/Backup and Sync.app" } diff --git a/host_vars/localhost-standardapps.yml b/host_vars/localhost-standardapps.yml index 59d67fd..7db10df 100644 --- a/host_vars/localhost-standardapps.yml +++ b/host_vars/localhost-standardapps.yml @@ -31,7 +31,7 @@ brew_packages: - { name: python, path: "{{ brew_bin }}/python3" } #- { name: pwgen, path: "{{ brew_bin }}/pwgen" } #- { name: jq, path: "{{ brew_bin }}/jq" } - - { name: gnupg, path: "{{ brew_bin }}/gpg" } + #- { name: gnupg, path: "{{ brew_bin }}/gpg" } #- { name: bash-completion, path: /usr/local/etc/profile.d/bash_completion.sh } #- { name: kubernetes-cli, path: "{{ brew_bin }}/kubectl" } #- { name: kubectx, path: "{{ brew_bin }}/kubectx" } @@ -65,7 +65,7 @@ brew_cask_packages: #- { name: krita, path: "/Applications/krita.app" } #- { name: obs, path: "/Applications/OBS.app" } #- { name: moonlight, path: "/Applications/Moonlight.app" } - - { name: zoomus, path: "/Applications/zoom.us.app" } + - { name: zoom, path: "/Applications/zoom.us.app" } - { name: discord, path: "/Applications/Discord.app" } - { name: google-backup-and-sync, path: "/Applications/Backup and Sync.app" } - { name: vlc, path: "/Applications/VLC.app" } @@ -74,9 +74,9 @@ brew_cask_packages: - { name: spotify, path: "/Applications/Spotify.app" } #- { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } -pip_packages: - - { name: ansible, path: "{{ pip_bin }}/ansible" } - #- { name: awscli, path: "{{ pip_bin }}/aws" } +#pip_packages: +# - { name: ansible, path: "{{ pip_bin }}/ansible" } +# - { name: awscli, path: "{{ pip_bin }}/aws" } # supports .zip and .dmg app_packages: diff --git a/templates/functions-example b/templates/functions-example new file mode 100644 index 0000000..3a3c391 --- /dev/null +++ b/templates/functions-example @@ -0,0 +1,17 @@ +function git.merge.master() { + cur_branch=$(git branch |grep ^* | cut -d\ -f2) + echo "Merging master into $cur_branch" + git checkout master + git pull --all + git checkout $cur_branch + git merge master +} + +function git.diff.origin() { + git diff @{upstream} +} + +function git.diff.push() { + git diff @{push} +} + From 0737cd5ab594828caccc58d3cfb11c09d81d923a Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Thu, 26 Aug 2021 15:32:33 +0200 Subject: [PATCH 36/51] Update readme and add `install.sh` --- install.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..f349f20 --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/zsh + +# install Homebrew +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + +# install ansible +brew install ansible From d420aac47a7a495af860d17a13e0a2bc25d399dd Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Thu, 26 Aug 2021 16:22:53 +0200 Subject: [PATCH 37/51] Support Ansible collections (#6) * Add feature to install ansible collections --- host_vars/localhost-example.yml | 7 +++++++ macdev.yml | 9 +++++++++ roles/ansible/tasks/main.yml | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 roles/ansible/tasks/main.yml diff --git a/host_vars/localhost-example.yml b/host_vars/localhost-example.yml index f0bf5d1..5be99d5 100644 --- a/host_vars/localhost-example.yml +++ b/host_vars/localhost-example.yml @@ -7,6 +7,7 @@ brew_multiuser: no # roles role_ssh: yes +role_ansible: yes role_pip: yes role_brew: yes role_app: no @@ -28,6 +29,12 @@ templates: shell_aliases: - { name: "localdev", cmd: "(cd ~/YOUR_MACDEV_DIRECTORY; ansible-playbook macdev.yml)" } +ansible_collections: + - { name: community.general } + # see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file + #- { name: community.docker, version: "=1.9.0" } + #- { name: community.kubernetes, source: "" } + brew_packages: - { name: python, path: /usr/local/bin/python3 } - { name: pwgen, path: /usr/local/bin/pwgen } diff --git a/macdev.yml b/macdev.yml index 181b673..acb1b95 100644 --- a/macdev.yml +++ b/macdev.yml @@ -1,9 +1,18 @@ --- - name: Simple macOS setup hosts: localhost + # set defaults + pre_tasks: + - set_fact: + role_ssh: "{{ role_ssh|default(false) }}" + role_ansible: "{{ role_ansible|default(false) }}" + role_pip: "{{ role_pip|default(false) }}" + role_brew: "{{ role_brew|default(false) }}" + role_app: "{{ role_app|default(false) }}" roles: - { role: env } - { role: ssh, when: role_ssh|bool } + - { role: ansible, when: role_ansible|bool } - { role: pip, when: role_pip|bool } - { role: brew, when: role_brew|bool } - { role: app, when: role_app|bool } diff --git a/roles/ansible/tasks/main.yml b/roles/ansible/tasks/main.yml new file mode 100644 index 0000000..73a8244 --- /dev/null +++ b/roles/ansible/tasks/main.yml @@ -0,0 +1,18 @@ +--- + +- name: Add ansible collections + shell: ansible-galaxy collection install {{ item.name }} --upgrade + with_items: "{{ ansible_collections }}" + when: (item.version is not defined or item.version == "") and + (item.source is not defined or item.source == "") + +- name: Add ansible collections with version + shell: ansible-galaxy collection install '{{ item.name }}:{{ item.version }}' --upgrade + with_items: "{{ ansible_collections }}" + when: item.version is defined and item.version != "" and + (item.source is not defined or item.source == "") + +- name: Add ansible collections from source + shell: ansible-galaxy collection install '{{ item.source }}' --upgrade + with_items: "{{ ansible_collections }}" + when: item.source is defined and item.source != "" From ccb3b4e90f7160c18878dc3addcb7b3f685054ef Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 25 Oct 2021 19:50:21 +0200 Subject: [PATCH 38/51] Add example config Example config I use for MacBook Air M1 --- host_vars/localhost-M1example.yaml | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 host_vars/localhost-M1example.yaml diff --git a/host_vars/localhost-M1example.yaml b/host_vars/localhost-M1example.yaml new file mode 100644 index 0000000..6b902ff --- /dev/null +++ b/host_vars/localhost-M1example.yaml @@ -0,0 +1,89 @@ +# this is pretty much my own config for my MacBook Air M1 +--- + +# roles +role_ssh: yes +role_ansible: true +role_pip: yes +role_brew: yes +role_app: no + +# files and templates: +# overwrite: replace file on target, if it exists +# shell: source file in .profile + +# files you want to copy to the target +#files: + #- { name: "file-example", path: "$HOME/file-example", overwrite: true, shell: false } + +# templates you want to copy to the target +templates: + # some shell functions I use for save time with regular tasks local or remote + # see https://levelup.gitconnected.com/the-biggest-time-saver-for-operators-is-dead-simple-9118a1a054b8?source=friends_link&sk=6dc96be1d06fb5ab2d3b1a999caacfa3 + - { name: "myfunctions.sh", path: "$HOME/bin/myfunctions.sh", overwrite: true, shell: true } + - { name: "home-functions.sh", path: "$HOME/bin/home-functions.sh", overwrite: true, shell: false } + # simply config for finicky, e.g. meet.google.com -> use Chrome + - { name: "finicky.js", path: "$HOME/.finicky.js", overwrite: true, shell: false } + +# instead of copying a file or template, you can define aliases one by one +shell_aliases: + - { name: "localbrew", cmd: "(cd ~/work/git/macdev; ansible-playbook macdev.yml)" } + +ansible_collections: + - { name: community.general } + # see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file + - { name: community.docker } + #- { name: community.kubernetes, version: "", source: "" } + + brew_packages: + - { name: gnupg, path: "{{brew_bin}}/gpg" } + - { name: jq, path: "{{brew_bin}}/jq" } + - { name: watch, path: "{{brew_bin}}/watch" } + - { name: gnupg, path: "{{brew_bin}}/gpg" } + - { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } + - { name: kubectx, path: "{{brew_bin}}/kubectx" } + - { name: helm, path: "{{brew_bin}}/helm" } + - { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" } + - { name: node, path: "{{brew_bin}}/node" } + - { name: telegraf, path: "{{brew_bin}}/telegraf" } + - { name: mtr, path: "{{brew_sbin}}/mtr" } + - { name: smartmontools, path: "{{brew_bin}}/smartctl" } + - { name: glances, path: "{{brew_bin}}/glances" } + - { name: hub, path: "{{brew_bin}}/hub" } + +brew_cask_packages: + - { name: docker, path: /Applications/Docker.app } + - { name: iterm2, path: /Applications/iTerm.app } + - { name: google-chrome, path: /Applications/Google Chrome.app } + - { name: atom, path: /Applications/Atom.app } + - { name: slack, path: /Applications/Slack.app } + - { name: macpass, path: /Applications/MacPass.app } + - { name: zoomus, path: /Applications/zoom.us.app } + #- { name: openoffice, path: /Applications/OpenOffice.app } + #- { name: libreoffice, path: "/Applications/LibreOffice.app" } + #- { name: gimp, path: /Applications/Gimp-2.10.app } + - { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } + - { name: spectacle, path: "/Applications/Spectacle.app" } + - { name: drawio, path: "/Applications/draw.io.app" } + - { name: postman, path: "/Applications/Postman.app" } + - { name: moonlight, path: "/Applications/Moonlight.app" } + - { name: krita, path: "/Applications/krita.app" } + - { name: spotify, path: "/Applications/Spotify.app" } + - { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } + - { name: monitorcontrol, path: "/Applications/MonitorControl.app" } + - { name: macs-fan-control, path: "/Applications/Macs Fan Control.app" } + #- { name: qsync-client, path: "/Applications/QSync Client.app" } + - { name: discord, path: "/Applications/Discord.app" } + - { name: google-drive, path: "/Applications/Google Drive.app" } + - { name: vlc, path: "/Applications/VLC.app" } + #- { name: virtualbox, path: "/Applications/VirtualBox.app" } + #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.26/Oracle_VM_VirtualBox_Extension_Pack-6.1.26.vbox-extpack" } + - { name: obsidian, path: "/Applications/Obsidian.app" } + - { name: mindforger, path: "/Applications/mindforger.app" } + #- { name: moom, path: "/Applications/Moom.app" } + - { name: obs, path: "/Applications/OBS.app" } + - { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" } + #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } + - { name: finicky, path: "/Applications/finicky.app" } + - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } + From 207a83cf781edbb9a292e2ad162eec8a050f2259 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 30 Oct 2021 17:35:56 +0200 Subject: [PATCH 39/51] Add PyCharm and GoLand --- host_vars/localhost-M1example.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/host_vars/localhost-M1example.yaml b/host_vars/localhost-M1example.yaml index 6b902ff..d6413b3 100644 --- a/host_vars/localhost-M1example.yaml +++ b/host_vars/localhost-M1example.yaml @@ -63,6 +63,8 @@ brew_cask_packages: #- { name: libreoffice, path: "/Applications/LibreOffice.app" } #- { name: gimp, path: /Applications/Gimp-2.10.app } - { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } + #- { name: pycharm, path: "/Applications/PyCharm.app" } + #- { name: goland, path: "/Applications/GoLand.app" } - { name: spectacle, path: "/Applications/Spectacle.app" } - { name: drawio, path: "/Applications/draw.io.app" } - { name: postman, path: "/Applications/Postman.app" } From ac7e94b9155f0b289503c4f5ab9f8ecc9512ec01 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 23 May 2022 00:15:12 +0200 Subject: [PATCH 40/51] Feature: macOS config (#7) Adding support for * system config * user config * optionally download localhost.yml --- host_vars/localhost-M1example.yaml | 45 ++++++- host_vars/localhost-drpsychick-jones.yml | 162 +++++++++++++++++++++++ host_vars/localhost-standardapps.yml | 50 ++++++- macdev.yml | 32 ++++- roles/config/tasks/main.yml | 56 ++++++++ roles/env/tasks/main.yml | 4 +- roles/system/tasks/main.yml | 40 ++++++ 7 files changed, 383 insertions(+), 6 deletions(-) create mode 100644 host_vars/localhost-drpsychick-jones.yml create mode 100644 roles/config/tasks/main.yml create mode 100644 roles/system/tasks/main.yml diff --git a/host_vars/localhost-M1example.yaml b/host_vars/localhost-M1example.yaml index d6413b3..3f9a81b 100644 --- a/host_vars/localhost-M1example.yaml +++ b/host_vars/localhost-M1example.yaml @@ -8,7 +8,50 @@ role_pip: yes role_brew: yes role_app: no -# files and templates: +## system configuration (requires sudo) +system: +# # set ComputerName, HostName and NetBIOS Name +# hostname: example + # sudo systemsetup -help + systemsetup: +# - { key: "-setrestartfreeze", value: "on" } +# - { key: "-setdisplaysleep", value: "10" } + loginwindow: +# - { key: "AdminHostInfo", value: "HostName" } +# - { key: "GuestEnabled", value: "0" } + generic: +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + +## user configuration (must be run per user) +config: + # domain = NSGlobalDomain + global: +# - { key: "InitialKeyRepeat", int: 15 } +# - { key: "KeyRepeat", int: 1 } + generic: +# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } + # domain = com.apple.finder + finder: + # available views: `icnv`, `clmv`, `Flwv`, `Nlsv` +# - { key: "FXPreferredViewStyle", string: "Nlsv" } + # domain = com.apple.dock + dock: + # https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356 +# - { key: "magnification", int: 1 } +# - { key: "tilesize", int: 32 } +# - { key: "largesize", int: 128 } +# - { key: "autohide", int: 1 } +# - { key: "wvous-tl-corner", int: 5 } +# - { key: "wvous-tl-modifier", int: 0 } +# - { key: "wvous-tr-corner", int: 11 } +# - { key: "wvous-tr-modifier", int: 0 } +# - { key: "wvous-bl-corner", int: 3 } +# - { key: "wvous-bl-modifier", int: 0 } +# - { key: "wvous-br-corner", int: 2 } +# - { key: "wvous-br-modifier", int: 0 } + +## user files and templates: # overwrite: replace file on target, if it exists # shell: source file in .profile diff --git a/host_vars/localhost-drpsychick-jones.yml b/host_vars/localhost-drpsychick-jones.yml new file mode 100644 index 0000000..d771915 --- /dev/null +++ b/host_vars/localhost-drpsychick-jones.yml @@ -0,0 +1,162 @@ +--- + +# roles +role_ssh: yes +role_sys: yes +role_cfg: yes +role_ansible: true +role_pip: yes +role_brew: yes +role_app: no + +config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-jones.yml" + +system: + hostname: jones + # sudo systemsetup -help + systemsetup: + - { key: "-setrestartfreeze", value: "on" } + - { key: "-setdisplaysleep", value: "10" } + # domain = /Library/Preferences/com.apple.loginwindow + loginwindow: + - { key: "AdminHostInfo", value: "HostName" } + - { key: "GuestEnabled", value: "0" } + generic: + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + +config: + # domain = NSGlobalDomain + global: + - { key: "InitialKeyRepeat", int: 20 } + - { key: "KeyRepeat", int: 1 } + generic: + - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } + - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", bool: true } + - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true } + - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true } + - { domain: "com.apple.gamed", key: "Disabled", bool: true } + # domain = com.apple.finder + finder: + - { key: "FXPreferredViewStyle", string: "Nlsv" } + # domain = com.apple.dock + dock: + - { key: "magnification", bool: true } + - { key: "tilesize", int: 32 } + - { key: "largesize", int: 128 } + - { key: "autohide", bool: true } + - { key: "showhidden", bool: true } + - { key: "wvous-tl-corner", int: 5 } + - { key: "wvous-tl-modifier", int: 0 } + - { key: "wvous-tr-corner", int: 11 } + - { key: "wvous-tr-modifier", int: 0 } + - { key: "wvous-bl-corner", int: 3 } + - { key: "wvous-bl-modifier", int: 0 } + - { key: "wvous-br-corner", int: 2 } + - { key: "wvous-br-modifier", int: 0 } + - { key: "expose-animation-duration", float: 0.5 } + +## user files and templates: +# overwrite: replace file on target, if it exists +# source: "interactive" or "login" + +# files you want to copy to the target +files: + #- { name: "file-example", path: "$HOME/file-example", overwrite: true, shell: false } + +# templates you want to copy to the target +templates: + - { name: "myfunctions.sh", path: "$HOME/bin/myfunctions.sh", overwrite: true, source: "interactive" } + - { name: "home-functions.sh", path: "$HOME/bin/home-functions.sh", overwrite: true } + - { name: "finicky.js", path: "$HOME/.finicky.js", overwrite: true } + - { name: "gitconfig", path: "$HOME/.gitconfig", overwrite: true } + - { name: "gitconfig-work", path: "$HOME/.gitconfig-work", overwrite: true } + - { name: "gitconfig-private", path: "$HOME/.gitconfig-private", overwrite: true } + +# instead of copying a file or template, you can define aliases one by one +shell_aliases: + - { name: "updatemac", cmd: "(cd ~/work/git/macdev; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" } + - { name: "rancherVM", cmd: 'LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0' } + - { name: "fixvpn", cmd: "sudo route delete -host 85.190.148.133 192.168.1.200; sudo route add -host 85.190.148.133 192.168.1.200" } + +ansible_collections: + - { name: community.general } + # see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file + - { name: community.docker } + - { name: community.kubernetes } # , version: "", source: "" } + +brew_packages: + - { name: gnupg, path: "{{brew_bin}}/gpg" } + - { name: jq, path: "{{brew_bin}}/jq" } + - { name: watch, path: "{{brew_bin}}/watch" } + - { name: gnupg, path: "{{brew_bin}}/gpg" } + #- { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } # conflicts with Rancher Desktop + #- { name: kubectx, path: "{{brew_bin}}/kubectx" } + #- { name: helm, path: "{{brew_bin}}/helm" } # conflicts with Rancher Desktop + - { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" } + - { name: node, path: "{{brew_bin}}/node" } + - { name: telegraf, path: "{{brew_bin}}/telegraf" } + - { name: mtr, path: "{{brew_sbin}}/mtr" } + - { name: smartmontools, path: "{{brew_bin}}/smartctl" } + - { name: glances, path: "{{brew_bin}}/glances" } + - { name: hub, path: "{{brew_bin}}/hub" } + - { name: qemu, path: "{{brew_bin}}/qemu-img" } + - { name: k3d, path: "{{brew_bin}}/k3d" } + - { name: kustomize, path: "{{brew_bin}}/kustomize" } + - { name: kubeval, path: "{{brew_bin}}/kubeval" } + - { name: kubeseal, path: "{{brew_bin}}/kubeseal" } + - { name: pwgen, path: "{{brew_bin}}/pwgen" } + - { name: yamllint, path: "{{brew_bin}}/yamllint" } + +brew_cask_packages: + #- { name: docker, path: /Applications/Docker.app } + - { name: iterm2, path: /Applications/iTerm.app } + - { name: google-chrome, path: /Applications/Google Chrome.app } + - { name: atom, path: /Applications/Atom.app } + - { name: slack, path: /Applications/Slack.app } + - { name: macpass, path: /Applications/MacPass.app } + - { name: zoomus, path: /Applications/zoom.us.app } + #- { name: openoffice, path: /Applications/OpenOffice.app } + #- { name: libreoffice, path: "/Applications/LibreOffice.app" } + #- { name: gimp, path: /Applications/Gimp-2.10.app } + #- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } + - { name: pycharm, path: "/Applications/PyCharm.app" } + - { name: goland, path: "/Applications/GoLand.app" } + - { name: tunnelblick, path: "/Applications/Tunnelblick.app" } + - { name: spectacle, path: "/Applications/Spectacle.app" } + - { name: drawio, path: "/Applications/draw.io.app" } + - { name: postman, path: "/Applications/Postman.app" } + - { name: moonlight, path: "/Applications/Moonlight.app" } + - { name: krita, path: "/Applications/krita.app" } + - { name: spotify, path: "/Applications/Spotify.app" } + - { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } + - { name: monitorcontrol, path: "/Applications/MonitorControl.app" } + - { name: macs-fan-control, path: "/Applications/Macs Fan Control.app" } + - { name: qsync-client, path: "/Applications/QSync Client.app" } + - { name: discord, path: "/Applications/Discord.app" } + - { name: google-drive, path: "/Applications/Google Drive.app" } + - { name: vlc, path: "/Applications/VLC.app" } + #- { name: virtualbox, path: "/Applications/VirtualBox.app" } + #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" } + - { name: obsidian, path: "/Applications/Obsidian.app" } + - { name: mindforger, path: "/Applications/mindforger.app" } + - { name: moom, path: "/Applications/Moom.app" } + - { name: obs, path: "/Applications/OBS.app" } + - { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" } + #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } + - { name: finicky, path: "/Applications/finicky.app" } + - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } + - { name: utm, path: "/Applications/UTM.app" } + - { name: minecraft, path: "/Applications/Minecraft.app" } + - { name: curseforge, path: "/Applications/CurseForge.app" } + - { name: rancher, path: "/Applications/Rancher Desktop.app" } + - { name: 1password, path: "/Applications/1Password 7.app" } + +pip_packages: + - { name: yamale, path: "{{pip_bin}}/yamale" } +# - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" } +# - { name: ansible, path: /usr/local/bin/ansible } +# - { name: awscli, path: /usr/local/bin/aws } + +# supports .zip and .dmg +app_packages: diff --git a/host_vars/localhost-standardapps.yml b/host_vars/localhost-standardapps.yml index 7db10df..b975787 100644 --- a/host_vars/localhost-standardapps.yml +++ b/host_vars/localhost-standardapps.yml @@ -6,11 +6,57 @@ # roles role_ssh: no +role_sys: no +role_cfg: no +role_ansible: true role_pip: yes role_brew: yes role_app: no -# files and templates: +## system configuration (requires sudo) +system: +# # set ComputerName, HostName and NetBIOS Name +# hostname: example + # sudo systemsetup -help + systemsetup: +# - { key: "-setrestartfreeze", value: "on" } +# - { key: "-setdisplaysleep", value: "10" } + loginwindow: +# - { key: "AdminHostInfo", value: "HostName" } +# - { key: "GuestEnabled", value: "0" } + generic: +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + +## user configuration (must be run per user) +config: + # domain = NSGlobalDomain + global: +# - { key: "InitialKeyRepeat", int: 15 } +# - { key: "KeyRepeat", int: 1 } + generic: +# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } + # domain = com.apple.finder + finder: + # available views: `icnv`, `clmv`, `Flwv`, `Nlsv` + - { key: "FXPreferredViewStyle", string: "Nlsv" } + # domain = com.apple.dock + dock: + # https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356 +# - { key: "magnification", int: 1 } +# - { key: "tilesize", int: 32 } +# - { key: "largesize", int: 128 } +# - { key: "autohide", int: 1 } +# - { key: "wvous-tl-corner", int: 5 } +# - { key: "wvous-tl-modifier", int: 0 } +# - { key: "wvous-tr-corner", int: 11 } +# - { key: "wvous-tr-modifier", int: 0 } +# - { key: "wvous-bl-corner", int: 3 } +# - { key: "wvous-bl-modifier", int: 0 } +# - { key: "wvous-br-corner", int: 2 } +# - { key: "wvous-br-modifier", int: 0 } + +## user files and templates: # overwrite: replace file on target, if it exists # shell: source file in .profile @@ -67,7 +113,7 @@ brew_cask_packages: #- { name: moonlight, path: "/Applications/Moonlight.app" } - { name: zoom, path: "/Applications/zoom.us.app" } - { name: discord, path: "/Applications/Discord.app" } - - { name: google-backup-and-sync, path: "/Applications/Backup and Sync.app" } + - { name: google-drive, path: "/Applications/Google Drive.app" } - { name: vlc, path: "/Applications/VLC.app" } #- { name: iina, path: "/Applications/Iina.app" } #- { name: background-music, path: "/Applications/Background Music.app" } diff --git a/macdev.yml b/macdev.yml index acb1b95..a7d4712 100644 --- a/macdev.yml +++ b/macdev.yml @@ -1,17 +1,47 @@ --- -- name: Simple macOS setup +- name: Download config + hosts: localhost + tasks: + - name: Download config + get_url: + url: "{{ config_url }}" + dest: "{{ playbook_dir }}/host_vars/localhost.yml" + register: config_download + when: config_url is defined + - fail: + when: config_download is changed + +- name: Sudo check hosts: localhost # set defaults pre_tasks: - set_fact: role_ssh: "{{ role_ssh|default(false) }}" + role_sys: "{{ role_sys|default(false) }}" + role_cfg: "{{ role_cfg|default(false) }}" role_ansible: "{{ role_ansible|default(false) }}" role_pip: "{{ role_pip|default(false) }}" role_brew: "{{ role_brew|default(false) }}" role_app: "{{ role_app|default(false) }}" + tasks: + - name: Check if sudo works + shell: sudo echo "sudo works" + become: yes + become_user: root + register: sudo_check + ignore_errors: true + when: role_sys + - debug: msg="Run 'sudo echo' to fix this." + failed_when: true + when: role_sys and sudo_check is failed + +- name: Simple macOS setup + hosts: localhost roles: - { role: env } - { role: ssh, when: role_ssh|bool } + - { role: system, when: role_sys|bool } + - { role: config, when: role_cfg|bool } - { role: ansible, when: role_ansible|bool } - { role: pip, when: role_pip|bool } - { role: brew, when: role_brew|bool } diff --git a/roles/config/tasks/main.yml b/roles/config/tasks/main.yml new file mode 100644 index 0000000..cb1dedb --- /dev/null +++ b/roles/config/tasks/main.yml @@ -0,0 +1,56 @@ +--- +- name: Check vars + debug: msg="`config` is defined" + failed_when: config is not defined + +- name: Global configuration + shell: | + defaults write NSGlobalDomain {{ item.key }} \ + {{ "-int "+item.int|string if item.int is defined }} \ + {{ "-float "+item.float|string if item.float is defined }} \ + {{ "-bool "+item.bool|string if item.bool is defined }} \ + {{ "-string "+item.string if item.string is defined }} + with_items: "{{ config.global }}" + register: global_config + when: config.global is defined + +- name: Generic configuration + shell: | + defaults write {{ item.domain }} {{ item.key }} \ + {{ "-int "+item.int|string if item.int is defined }} \ + {{ "-float "+item.float|string if item.float is defined }} \ + {{ "-bool "+item.bool|string if item.bool is defined }} \ + {{ "-string "+item.string if item.string is defined }} + with_items: "{{ config.generic }}" + register: generic_config + when: config.generic is defined and item.domain is defined + +- name: Configure Finder + shell: | + defaults write com.apple.finder {{ item.key }} \ + {{ "-int "+item.int|string if item.int is defined }} \ + {{ "-float "+item.float|string if item.float is defined }} \ + {{ "-bool "+item.bool|string if item.bool is defined }} \ + {{ "-string "+item.string if item.string is defined }} + with_items: "{{ config.finder }}" + register: finder_config + when: config.finder is defined + +- name: Restart Finder + shell: killall Finder + when: finder_config is changed + +- name: Configure Dock + shell: | + defaults write com.apple.dock {{ item.key }} \ + {{ "-int "+item.int|string if item.int is defined }} \ + {{ "-float "+item.float|string if item.float is defined }} \ + {{ "-bool "+item.bool|string if item.bool is defined }} \ + {{ "-string "+item.string if item.string is defined }} + with_items: "{{ config.dock }}" + register: dock_config + when: config.dock is defined + +- name: Restart Dock + shell: killall Dock + when: dock_config is changed diff --git a/roles/env/tasks/main.yml b/roles/env/tasks/main.yml index a7d5910..e6ec59b 100644 --- a/roles/env/tasks/main.yml +++ b/roles/env/tasks/main.yml @@ -83,7 +83,7 @@ line: "source {{ item.path }}" create: yes with_items: "{{ files }}" - when: files|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") + when: files|length > 0 and item.source|default("") == "interactive" # templates # fails if a file exists that should not be overwritten @@ -115,4 +115,4 @@ line: "source {{ item.path }}" create: yes with_items: "{{ templates }}" - when: templates|length > 0 and (item.shell|default(false) or item.source|default("") == "interactive") + when: templates|length > 0 and item.source|default("") == "interactive" diff --git a/roles/system/tasks/main.yml b/roles/system/tasks/main.yml new file mode 100644 index 0000000..2b1d673 --- /dev/null +++ b/roles/system/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: Set hostname + shell: | + systemsetup -setcomputername {{ system.hostname }}; + scutil --set ComputerName {{ system.hostname }}; + scutil --set HostName {{ system.hostname }} + scutil --set LocalHostName {{ system.hostname }} + defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string {{ system.hostname|lower }} + become: yes + become_user: "root" + when: system.hostname is defined + +- name: System Setup + shell: | + systemsetup {{ item.key }} {{ item.value }} + with_items: "{{ system.systemsetup }}" + become: yes + become_user: "root" + when: system.systemsetup is defined + +- name: Generic configuration + shell: | + defaults write {{ item.domain }} {{ item.key }} \ + {{ "-int "+item.int|string if item.int is defined }} \ + {{ "-float "+item.float|string if item.float is defined }} \ + {{ "-bool "+item.bool|string if item.bool is defined }} \ + {{ "-string "+item.string if item.string is defined }} + with_items: "{{ system.generic }}" + become: yes + become_user: "root" + register: generic_config + when: system.generic is defined and item.domain is defined + +- name: Configure Login Window + shell: defaults write /Library/Preferences/com.apple.loginwindow {{ item.key }} {{ item.value }} + with_items: "{{ system.loginwindow }}" + become: yes + become_user: "root" + when: system.loginwindow is defined + From 12c1be2739331b866946dcd179f3128662ebee58 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 23 May 2022 00:28:27 +0200 Subject: [PATCH 41/51] chore: cleanup README --- README.md | 7 ++++++- host_vars/localhost-drpsychick-jones.yml | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e7e0b8e..d383a38 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,14 @@ It is **not** meant to be used for linux or windows environments and **not** mea ## configure it * use `host_vars/localhost-example.yml` as a base and en-/disable roles, add/remove packages to install via pip or homebrew ... * save it as `host_vars/localhost.yml` to enable it +* OR (see below): provide a URL to download your config from: `-e config_url=http://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-example.yml` ## run it -`ansible-playbook macdev.yml` +```shell +ansible-playbook macdev.yml +# OR with config URL (must re-run after download) +ansible-playbook macdev.yml -e config_url=http://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-example.yml +``` ## maintain it You want to install a new package? Edit your `host_vars/localhost.yml`, then simply run your alias `localdev` (see `host_vars/localhost-example.yml`) or the above command. diff --git a/host_vars/localhost-drpsychick-jones.yml b/host_vars/localhost-drpsychick-jones.yml index d771915..765fad3 100644 --- a/host_vars/localhost-drpsychick-jones.yml +++ b/host_vars/localhost-drpsychick-jones.yml @@ -115,7 +115,7 @@ brew_cask_packages: - { name: atom, path: /Applications/Atom.app } - { name: slack, path: /Applications/Slack.app } - { name: macpass, path: /Applications/MacPass.app } - - { name: zoomus, path: /Applications/zoom.us.app } + - { name: zoom, path: /Applications/zoom.us.app } #- { name: openoffice, path: /Applications/OpenOffice.app } #- { name: libreoffice, path: "/Applications/LibreOffice.app" } #- { name: gimp, path: /Applications/Gimp-2.10.app } @@ -140,7 +140,7 @@ brew_cask_packages: #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" } - { name: obsidian, path: "/Applications/Obsidian.app" } - { name: mindforger, path: "/Applications/mindforger.app" } - - { name: moom, path: "/Applications/Moom.app" } + #- { name: moom, path: "/Applications/Moom.app" } - { name: obs, path: "/Applications/OBS.app" } - { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" } #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } @@ -155,8 +155,8 @@ brew_cask_packages: pip_packages: - { name: yamale, path: "{{pip_bin}}/yamale" } # - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" } -# - { name: ansible, path: /usr/local/bin/ansible } -# - { name: awscli, path: /usr/local/bin/aws } +# - { name: ansible, path: "{{pip_bin}}/ansible" } +# - { name: awscli, path: "{{pip_bin}}/aws" } # supports .zip and .dmg app_packages: From 3f29bbd021ee17cc7feb4833c299c51af4657402 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 23 May 2022 00:35:50 +0200 Subject: [PATCH 42/51] chore: add link to repos that inspired me --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d383a38..16e68df 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,6 @@ You want to install a new package? Edit your `host_vars/localhost.yml`, then sim # setup ENV for mac and ansible: see https://gist.github.com/DrPsychick/847ea32c876fda2337e79096a8a23176 + +# inspired by +* https://github.com/roberth1988/osx-bootstrap From 9970bbea7b864132e7ff8e6a1e71aa85fcb46855 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sun, 12 Jun 2022 23:12:04 +0200 Subject: [PATCH 43/51] feat: support timemachine destination and exclusions --- host_vars/localhost-drpsychick-jones.yml | 13 +++++++++- roles/system/tasks/main.yml | 3 +++ roles/system/tasks/timemachine.yml | 33 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 roles/system/tasks/timemachine.yml diff --git a/host_vars/localhost-drpsychick-jones.yml b/host_vars/localhost-drpsychick-jones.yml index 765fad3..1fa9701 100644 --- a/host_vars/localhost-drpsychick-jones.yml +++ b/host_vars/localhost-drpsychick-jones.yml @@ -24,7 +24,18 @@ system: generic: - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } - + timemachine: + destination: "smb://muc@neb%28TimeMachine%29._smb._tcp.local./macbackups" + exclusions: + - /Users/muc/Documents + - /Users/muc/SharedDocs + - /Users/muc/Library/Application Support/MobileSync + - /Users/muc/Library/Containers/com.docker.docker + - /Users/muc/Library/Developer/CoreSimulator/Caches + - /Users/muc/Library/iTunes/iPhone Software Updates + - /Users/pascal/Library/Containers/com.docker.docker + - /Users/dlazy/CurseForge + - /Users/dlazy/Documents config: # domain = NSGlobalDomain global: diff --git a/roles/system/tasks/main.yml b/roles/system/tasks/main.yml index 2b1d673..79b5c6d 100644 --- a/roles/system/tasks/main.yml +++ b/roles/system/tasks/main.yml @@ -1,4 +1,5 @@ --- + - name: Set hostname shell: | systemsetup -setcomputername {{ system.hostname }}; @@ -38,3 +39,5 @@ become_user: "root" when: system.loginwindow is defined +- include: timemachine.yml + when: system.timemachine is defined \ No newline at end of file diff --git a/roles/system/tasks/timemachine.yml b/roles/system/tasks/timemachine.yml new file mode 100644 index 0000000..e83a5b0 --- /dev/null +++ b/roles/system/tasks/timemachine.yml @@ -0,0 +1,33 @@ +--- + +- name: Check TimeMachine destination + shell: > + tmutil destinationinfo | grep URL | awk '{print $3}' + become: yes + become_user: "root" + register: timemachine_destination + when: system.timemachine.destination is defined + +- name: Configure TimeMachine destination + shell: > + tmutil setdestination {{ system.timemachine.destination|quote }} + become: yes + become_user: "root" + when: system.timemachine.destination is defined and timemachine_destination.stdout != system.timemachine.destination + +# tmutil: isexcluded requires Full Disk Access privileges. +# -> run ansible in your normal terminal +- name: Add exclusions + shell: > + tmutil isexcluded {{ item|quote }} || exit 1; + included=$(tmutil isexcluded {{ item|quote }} | grep 'Included'); + if [ -n "$included" ]; then + tmutil addexclusion {{ item|quote }} && echo "done"; + fi + with_items: "{{ system.timemachine.exclusions }}" + become: yes + become_user: "root" + register: tm_exclude + when: system.timemachine.exclusions is defined + changed_when: tm_exclude.stdout == "done" + From fc25df5f9520283916611954be34c9a5750e49de Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Fri, 24 Jun 2022 23:40:47 +0200 Subject: [PATCH 44/51] add brew packages --- host_vars/localhost-drpsychick-jones.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/host_vars/localhost-drpsychick-jones.yml b/host_vars/localhost-drpsychick-jones.yml index 1fa9701..206c0f6 100644 --- a/host_vars/localhost-drpsychick-jones.yml +++ b/host_vars/localhost-drpsychick-jones.yml @@ -88,7 +88,7 @@ templates: shell_aliases: - { name: "updatemac", cmd: "(cd ~/work/git/macdev; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" } - { name: "rancherVM", cmd: 'LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0' } - - { name: "fixvpn", cmd: "sudo route delete -host 85.190.148.133 192.168.1.200; sudo route add -host 85.190.148.133 192.168.1.200" } + - { name: "fixvpn", cmd: "sudo route delete -host 85.190.148.133 192.168.1.1; sudo route add -host 85.190.148.133 192.168.1.1" } ansible_collections: - { name: community.general } @@ -118,6 +118,8 @@ brew_packages: - { name: kubeseal, path: "{{brew_bin}}/kubeseal" } - { name: pwgen, path: "{{brew_bin}}/pwgen" } - { name: yamllint, path: "{{brew_bin}}/yamllint" } + - { name: molecule, path: "{{brew_bin}}/molecule" } + - { name: pre-commit, path: "{{brew_bin}}/pre-commit" } brew_cask_packages: #- { name: docker, path: /Applications/Docker.app } From b96911914354d70fcb4b934bab2403408b8832bf Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 9 Jul 2022 16:03:46 +0200 Subject: [PATCH 45/51] fix: get prefix from brew --prefix add: configs for different hosts --- ...jones.yml => localhost-drpsychick-neo.yml} | 24 ++- host_vars/localhost-drpsychick-trinity.yml | 187 ++++++++++++++++++ 2 files changed, 205 insertions(+), 6 deletions(-) rename host_vars/{localhost-drpsychick-jones.yml => localhost-drpsychick-neo.yml} (89%) create mode 100644 host_vars/localhost-drpsychick-trinity.yml diff --git a/host_vars/localhost-drpsychick-jones.yml b/host_vars/localhost-drpsychick-neo.yml similarity index 89% rename from host_vars/localhost-drpsychick-jones.yml rename to host_vars/localhost-drpsychick-neo.yml index 206c0f6..21a0ec2 100644 --- a/host_vars/localhost-drpsychick-jones.yml +++ b/host_vars/localhost-drpsychick-neo.yml @@ -9,18 +9,18 @@ role_pip: yes role_brew: yes role_app: no -config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-jones.yml" +config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-trinity.yml" system: - hostname: jones + hostname: neo # sudo systemsetup -help systemsetup: - { key: "-setrestartfreeze", value: "on" } - { key: "-setdisplaysleep", value: "10" } # domain = /Library/Preferences/com.apple.loginwindow - loginwindow: - - { key: "AdminHostInfo", value: "HostName" } - - { key: "GuestEnabled", value: "0" } +# loginwindow: +# - { key: "AdminHostInfo", value: "HostName" } +# - { key: "GuestEnabled", value: "0" } generic: - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } @@ -36,6 +36,8 @@ system: - /Users/pascal/Library/Containers/com.docker.docker - /Users/dlazy/CurseForge - /Users/dlazy/Documents + +# Per user configuration config: # domain = NSGlobalDomain global: @@ -47,6 +49,14 @@ config: - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true } - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true } - { domain: "com.apple.gamed", key: "Disabled", bool: true } + # touchpad configuration + - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", bool: true } + # menu clock configuration + - { domain: "com.apple.menuextra.clock", key: "DateFormat", string: "EEE\\ d\\ MMM\\ 'at'\\ HH:mm:ss" } + - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", int: 0 } + - { domain: "com.apple.menuextra.clock", key: "Show24Hour", int: 1 } + - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", int: 1 } + - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", int: 1 } # requires restart of ??? # domain = com.apple.finder finder: - { key: "FXPreferredViewStyle", string: "Nlsv" } @@ -163,7 +173,9 @@ brew_cask_packages: - { name: minecraft, path: "/Applications/Minecraft.app" } - { name: curseforge, path: "/Applications/CurseForge.app" } - { name: rancher, path: "/Applications/Rancher Desktop.app" } - - { name: 1password, path: "/Applications/1Password 7.app" } + - { name: 1password, path: "/Applications/1Password.app" } + - { name: vnc-viewer, path: "/Applications/VNC Viewer.app" } + - { name: deepl, path: "/Applications/Deepl.app" } pip_packages: - { name: yamale, path: "{{pip_bin}}/yamale" } diff --git a/host_vars/localhost-drpsychick-trinity.yml b/host_vars/localhost-drpsychick-trinity.yml new file mode 100644 index 0000000..2d4ebff --- /dev/null +++ b/host_vars/localhost-drpsychick-trinity.yml @@ -0,0 +1,187 @@ +--- + +# roles +role_ssh: yes +role_sys: yes +role_cfg: yes +role_ansible: true +role_pip: yes +role_brew: yes +role_app: no + +config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-trinity.yml" + +system: + hostname: trinity + # sudo systemsetup -help + systemsetup: + - { key: "-setrestartfreeze", value: "on" } + - { key: "-setdisplaysleep", value: "10" } + # domain = /Library/Preferences/com.apple.loginwindow +# loginwindow: +# - { key: "AdminHostInfo", value: "HostName" } +# - { key: "GuestEnabled", value: "0" } + generic: + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + timemachine: + destination: "smb://muc@neb%28TimeMachine%29._smb._tcp.local./macbackups" + exclusions: + - /Users/muc/Documents + - /Users/muc/SharedDocs + - /Users/muc/Library/Application Support/MobileSync + - /Users/muc/Library/Containers/com.docker.docker + - /Users/muc/Library/Developer/CoreSimulator/Caches + - /Users/muc/Library/iTunes/iPhone Software Updates + - /Users/pascal/Library/Containers/com.docker.docker + - /Users/dlazy/CurseForge + - /Users/dlazy/Documents + +# Per user configuration +config: + # domain = NSGlobalDomain + global: + - { key: "InitialKeyRepeat", int: 20 } + - { key: "KeyRepeat", int: 1 } + generic: + - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } + - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", bool: true } + - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true } + - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true } + - { domain: "com.apple.gamed", key: "Disabled", bool: true } + # touchpad configuration + - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", bool: true } + # menu clock configuration + - { domain: "com.apple.menuextra.clock", key: "DateFormat", string: "EEE\\ d\\ MMM\\ 'at'\\ HH:mm:ss" } + - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", int: 0 } + - { domain: "com.apple.menuextra.clock", key: "Show24Hour", int: 1 } + - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", int: 1 } + - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", int: 1 } # requires restart of ??? + # domain = com.apple.finder + finder: + - { key: "FXPreferredViewStyle", string: "Nlsv" } + # domain = com.apple.dock + dock: + - { key: "magnification", bool: true } + - { key: "tilesize", int: 32 } + - { key: "largesize", int: 128 } + - { key: "autohide", bool: true } + - { key: "showhidden", bool: true } + - { key: "wvous-tl-corner", int: 5 } + - { key: "wvous-tl-modifier", int: 0 } + - { key: "wvous-tr-corner", int: 11 } + - { key: "wvous-tr-modifier", int: 0 } + - { key: "wvous-bl-corner", int: 3 } + - { key: "wvous-bl-modifier", int: 0 } + - { key: "wvous-br-corner", int: 2 } + - { key: "wvous-br-modifier", int: 0 } + - { key: "expose-animation-duration", float: 0.5 } + +## user files and templates: +# overwrite: replace file on target, if it exists +# source: "interactive" or "login" + +# files you want to copy to the target +files: + #- { name: "file-example", path: "$HOME/file-example", overwrite: true, shell: false } + +# templates you want to copy to the target +templates: + - { name: "myfunctions.sh", path: "$HOME/bin/myfunctions.sh", overwrite: true, source: "interactive" } + - { name: "home-functions.sh", path: "$HOME/bin/home-functions.sh", overwrite: true } + - { name: "finicky.js", path: "$HOME/.finicky.js", overwrite: true } + - { name: "gitconfig", path: "$HOME/.gitconfig", overwrite: true } + - { name: "gitconfig-work", path: "$HOME/.gitconfig-work", overwrite: true } + - { name: "gitconfig-private", path: "$HOME/.gitconfig-private", overwrite: true } + +# instead of copying a file or template, you can define aliases one by one +shell_aliases: + - { name: "updatemac", cmd: "(cd ~/work/git/macdev; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" } + - { name: "rancherVM", cmd: 'LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0' } + - { name: "fixvpn", cmd: "sudo route delete -host 85.190.148.133 192.168.1.1; sudo route add -host 85.190.148.133 192.168.1.1" } + +ansible_collections: + - { name: community.general } + # see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file + - { name: community.docker } + - { name: community.kubernetes } # , version: "", source: "" } + +brew_packages: + - { name: gnupg, path: "{{brew_bin}}/gpg" } + - { name: jq, path: "{{brew_bin}}/jq" } + - { name: watch, path: "{{brew_bin}}/watch" } + - { name: gnupg, path: "{{brew_bin}}/gpg" } + #- { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } # conflicts with Rancher Desktop + #- { name: kubectx, path: "{{brew_bin}}/kubectx" } + #- { name: helm, path: "{{brew_bin}}/helm" } # conflicts with Rancher Desktop + - { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" } + - { name: node, path: "{{brew_bin}}/node" } + - { name: telegraf, path: "{{brew_bin}}/telegraf" } + - { name: mtr, path: "{{brew_sbin}}/mtr" } + - { name: smartmontools, path: "{{brew_bin}}/smartctl" } + - { name: glances, path: "{{brew_bin}}/glances" } + - { name: hub, path: "{{brew_bin}}/hub" } + - { name: qemu, path: "{{brew_bin}}/qemu-img" } + - { name: k3d, path: "{{brew_bin}}/k3d" } + - { name: kustomize, path: "{{brew_bin}}/kustomize" } + - { name: kubeval, path: "{{brew_bin}}/kubeval" } + - { name: kubeseal, path: "{{brew_bin}}/kubeseal" } + - { name: pwgen, path: "{{brew_bin}}/pwgen" } + - { name: yamllint, path: "{{brew_bin}}/yamllint" } + - { name: molecule, path: "{{brew_bin}}/molecule" } + - { name: pre-commit, path: "{{brew_bin}}/pre-commit" } + +brew_cask_packages: + #- { name: docker, path: /Applications/Docker.app } + - { name: iterm2, path: /Applications/iTerm.app } + - { name: google-chrome, path: /Applications/Google Chrome.app } + - { name: atom, path: /Applications/Atom.app } + - { name: slack, path: /Applications/Slack.app } + - { name: macpass, path: /Applications/MacPass.app } + - { name: zoom, path: /Applications/zoom.us.app } + #- { name: openoffice, path: /Applications/OpenOffice.app } + #- { name: libreoffice, path: "/Applications/LibreOffice.app" } + #- { name: gimp, path: /Applications/Gimp-2.10.app } + #- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } + - { name: pycharm, path: "/Applications/PyCharm.app" } + - { name: goland, path: "/Applications/GoLand.app" } + - { name: tunnelblick, path: "/Applications/Tunnelblick.app" } + - { name: spectacle, path: "/Applications/Spectacle.app" } + - { name: drawio, path: "/Applications/draw.io.app" } + - { name: postman, path: "/Applications/Postman.app" } + - { name: moonlight, path: "/Applications/Moonlight.app" } + - { name: krita, path: "/Applications/krita.app" } + - { name: spotify, path: "/Applications/Spotify.app" } + - { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } + - { name: monitorcontrol, path: "/Applications/MonitorControl.app" } + - { name: macs-fan-control, path: "/Applications/Macs Fan Control.app" } + - { name: qsync-client, path: "/Applications/QSync Client.app" } + - { name: discord, path: "/Applications/Discord.app" } + - { name: google-drive, path: "/Applications/Google Drive.app" } + - { name: vlc, path: "/Applications/VLC.app" } + #- { name: virtualbox, path: "/Applications/VirtualBox.app" } + #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" } + - { name: obsidian, path: "/Applications/Obsidian.app" } + - { name: mindforger, path: "/Applications/mindforger.app" } + #- { name: moom, path: "/Applications/Moom.app" } + - { name: obs, path: "/Applications/OBS.app" } + - { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" } + #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } + - { name: finicky, path: "/Applications/finicky.app" } + - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } + - { name: utm, path: "/Applications/UTM.app" } + - { name: minecraft, path: "/Applications/Minecraft.app" } + - { name: curseforge, path: "/Applications/CurseForge.app" } + - { name: rancher, path: "/Applications/Rancher Desktop.app" } + - { name: 1password, path: "/Applications/1Password.app" } + - { name: vnc-viewer, path: "/Applications/VNC Viewer.app" } + - { name: deepl, path: "/Applications/Deepl.app" } + +pip_packages: + - { name: yamale, path: "{{pip_bin}}/yamale" } +# - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" } +# - { name: ansible, path: "{{pip_bin}}/ansible" } +# - { name: awscli, path: "{{pip_bin}}/aws" } + +# supports .zip and .dmg +app_packages: From 6e3c8d65d72fd03c20a3ff6307ad75dd6103f391 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 9 Jul 2022 16:05:02 +0200 Subject: [PATCH 46/51] fix: hostname --- host_vars/localhost-drpsychick-neo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host_vars/localhost-drpsychick-neo.yml b/host_vars/localhost-drpsychick-neo.yml index 21a0ec2..b43ffa2 100644 --- a/host_vars/localhost-drpsychick-neo.yml +++ b/host_vars/localhost-drpsychick-neo.yml @@ -9,7 +9,7 @@ role_pip: yes role_brew: yes role_app: no -config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-trinity.yml" +config_url: "https://raw.githubusercontent.com/DrPsychick/macdev/master/host_vars/localhost-drpsychick-neo.yml" system: hostname: neo From ecdf5c34ddf3e3ca92d12982411f1e02977851ed Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Sat, 9 Jul 2022 17:48:13 +0200 Subject: [PATCH 47/51] feat: make system/config tasks idempotent, update examples --- host_vars/localhost-M1example.yaml | 37 +++++------ host_vars/localhost-drpsychick-neo.yml | 73 ++++++++++------------ host_vars/localhost-drpsychick-trinity.yml | 63 ++++++++++--------- host_vars/localhost-standardapps.yml | 37 +++++------ macdev.yml | 1 + roles/ansible/tasks/main.yml | 6 ++ roles/config/tasks/main.yml | 44 +++++++------ roles/system/tasks/main.yml | 44 +++++++++---- roles/system/tasks/timemachine.yml | 1 + 9 files changed, 168 insertions(+), 138 deletions(-) diff --git a/host_vars/localhost-M1example.yaml b/host_vars/localhost-M1example.yaml index 3f9a81b..1ea9aa5 100644 --- a/host_vars/localhost-M1example.yaml +++ b/host_vars/localhost-M1example.yaml @@ -20,36 +20,37 @@ system: # - { key: "AdminHostInfo", value: "HostName" } # - { key: "GuestEnabled", value: "0" } generic: -# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } -# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", type: string, value: "HostName" } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", type: bool, value: 0 } ## user configuration (must be run per user) config: # domain = NSGlobalDomain global: -# - { key: "InitialKeyRepeat", int: 15 } -# - { key: "KeyRepeat", int: 1 } +# - { key: "InitialKeyRepeat", type: int, value: 15 } +# - { key: "KeyRepeat", type: int, value: 1 } generic: -# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } +# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", type: bool, value: 1 } # domain = com.apple.finder finder: # available views: `icnv`, `clmv`, `Flwv`, `Nlsv` -# - { key: "FXPreferredViewStyle", string: "Nlsv" } + - { key: "FXPreferredViewStyle", type: string, value: "Nlsv" } # domain = com.apple.dock dock: # https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356 -# - { key: "magnification", int: 1 } -# - { key: "tilesize", int: 32 } -# - { key: "largesize", int: 128 } -# - { key: "autohide", int: 1 } -# - { key: "wvous-tl-corner", int: 5 } -# - { key: "wvous-tl-modifier", int: 0 } -# - { key: "wvous-tr-corner", int: 11 } -# - { key: "wvous-tr-modifier", int: 0 } -# - { key: "wvous-bl-corner", int: 3 } -# - { key: "wvous-bl-modifier", int: 0 } -# - { key: "wvous-br-corner", int: 2 } -# - { key: "wvous-br-modifier", int: 0 } +# - { key: "magnification", type: int, value: 1 } +# - { key: "tilesize", type: int, value: 32 } +# - { key: "largesize", type: int, value: 128 } +# - { key: "autohide", type: int, value: 1 } + # hot corners: tl = top-left, br = bottom-right +# - { key: "wvous-tl-corner", type: int, value: 5 } +# - { key: "wvous-tl-modifier", type: int, value: 0 } +# - { key: "wvous-tr-corner", type: int, value: 11 } +# - { key: "wvous-tr-modifier", type: int, value: 0 } +# - { key: "wvous-bl-corner", type: int, value: 3 } +# - { key: "wvous-bl-modifier", type: int, value: 0 } +# - { key: "wvous-br-corner", type: int, value: 2 } +# - { key: "wvous-br-modifier", type: int, value: 0 } ## user files and templates: # overwrite: replace file on target, if it exists diff --git a/host_vars/localhost-drpsychick-neo.yml b/host_vars/localhost-drpsychick-neo.yml index b43ffa2..5d150c2 100644 --- a/host_vars/localhost-drpsychick-neo.yml +++ b/host_vars/localhost-drpsychick-neo.yml @@ -16,66 +16,61 @@ system: # sudo systemsetup -help systemsetup: - { key: "-setrestartfreeze", value: "on" } - - { key: "-setdisplaysleep", value: "10" } + - { key: "-setcomputersleep", value: "5" } + - { key: "-setdisplaysleep", value: "1" } # domain = /Library/Preferences/com.apple.loginwindow # loginwindow: # - { key: "AdminHostInfo", value: "HostName" } # - { key: "GuestEnabled", value: "0" } generic: - - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } - - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", type: string, value: "HostName" } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", type: bool, value: 0 } timemachine: destination: "smb://muc@neb%28TimeMachine%29._smb._tcp.local./macbackups" exclusions: - /Users/muc/Documents - - /Users/muc/SharedDocs - - /Users/muc/Library/Application Support/MobileSync - - /Users/muc/Library/Containers/com.docker.docker - - /Users/muc/Library/Developer/CoreSimulator/Caches - - /Users/muc/Library/iTunes/iPhone Software Updates - - /Users/pascal/Library/Containers/com.docker.docker - - /Users/dlazy/CurseForge - - /Users/dlazy/Documents + - /Users/Shared/SharedDocs + - /Users/snoopy/Documents # Per user configuration config: # domain = NSGlobalDomain global: - - { key: "InitialKeyRepeat", int: 20 } - - { key: "KeyRepeat", int: 1 } + - { key: "InitialKeyRepeat", type: int, value: 20 } + - { key: "KeyRepeat", type: int, value: 1 } generic: - - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } - - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", bool: true } - - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true } - - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true } - - { domain: "com.apple.gamed", key: "Disabled", bool: true } + - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", type: bool, value: 1 } + - { domain: "com.apple.gamed", key: "Disabled", type: bool, value: 1 } # touchpad configuration - - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", bool: true } + - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", type: bool, value: 1 } # menu clock configuration - - { domain: "com.apple.menuextra.clock", key: "DateFormat", string: "EEE\\ d\\ MMM\\ 'at'\\ HH:mm:ss" } - - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", int: 0 } - - { domain: "com.apple.menuextra.clock", key: "Show24Hour", int: 1 } - - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", int: 1 } - - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", int: 1 } # requires restart of ??? + - { domain: "com.apple.menuextra.clock", key: "DateFormat", type: string, value: "EEE d MMM 'at' HH:mm:ss" } + - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", type: int, value: 0 } + - { domain: "com.apple.menuextra.clock", key: "Show24Hour", type: int, value: 1 } + - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", type: int, value: 1 } + - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", type: int, value: 1 } # requires restart of ??? # domain = com.apple.finder finder: - - { key: "FXPreferredViewStyle", string: "Nlsv" } + - { key: "FXPreferredViewStyle", type: string, value: "Nlsv" } # domain = com.apple.dock dock: - - { key: "magnification", bool: true } - - { key: "tilesize", int: 32 } - - { key: "largesize", int: 128 } - - { key: "autohide", bool: true } - - { key: "showhidden", bool: true } - - { key: "wvous-tl-corner", int: 5 } - - { key: "wvous-tl-modifier", int: 0 } - - { key: "wvous-tr-corner", int: 11 } - - { key: "wvous-tr-modifier", int: 0 } - - { key: "wvous-bl-corner", int: 3 } - - { key: "wvous-bl-modifier", int: 0 } - - { key: "wvous-br-corner", int: 2 } - - { key: "wvous-br-modifier", int: 0 } - - { key: "expose-animation-duration", float: 0.5 } + - { key: "magnification", type: bool, value: 1 } + - { key: "tilesize", type: int, value: 32 } + - { key: "largesize", type: int, value: 128 } + - { key: "autohide", type: bool, value: 1 } + - { key: "showhidden", type: bool, value: 1 } + - { key: "wvous-tl-corner", type: int, value: 5 } + - { key: "wvous-tl-modifier", type: int, value: 0 } + - { key: "wvous-tr-corner", type: int, value: 11 } + - { key: "wvous-tr-modifier", type: int, value: 0 } + - { key: "wvous-bl-corner", type: int, value: 3 } + - { key: "wvous-bl-modifier", type: int, value: 0 } + - { key: "wvous-br-corner", type: int, value: 2 } + - { key: "wvous-br-modifier", type: int, value: 0 } + - { key: "expose-animation-duration", type: float, value: 0.5 } ## user files and templates: # overwrite: replace file on target, if it exists diff --git a/host_vars/localhost-drpsychick-trinity.yml b/host_vars/localhost-drpsychick-trinity.yml index 2d4ebff..883c4c2 100644 --- a/host_vars/localhost-drpsychick-trinity.yml +++ b/host_vars/localhost-drpsychick-trinity.yml @@ -16,14 +16,15 @@ system: # sudo systemsetup -help systemsetup: - { key: "-setrestartfreeze", value: "on" } - - { key: "-setdisplaysleep", value: "10" } + - { key: "-setcomputersleep", value: "5" } + - { key: "-setdisplaysleep", value: "1" } # domain = /Library/Preferences/com.apple.loginwindow # loginwindow: # - { key: "AdminHostInfo", value: "HostName" } # - { key: "GuestEnabled", value: "0" } generic: - - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } - - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", type: string, value: "HostName" } + - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", type: bool, value: 0 } timemachine: destination: "smb://muc@neb%28TimeMachine%29._smb._tcp.local./macbackups" exclusions: @@ -41,41 +42,41 @@ system: config: # domain = NSGlobalDomain global: - - { key: "InitialKeyRepeat", int: 20 } - - { key: "KeyRepeat", int: 1 } + - { key: "InitialKeyRepeat", type: int, value: 20 } + - { key: "KeyRepeat", type: int, value: 1 } generic: - - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } - - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", bool: true } - - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", bool: true } - - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", bool: true } - - { domain: "com.apple.gamed", key: "Disabled", bool: true } + - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "IncludeDevelopMenu", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "WebKitDeveloperExtrasEnabledPreferenceKey", type: bool, value: 1 } + - { domain: "com.apple.Safari", key: "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled", type: bool, value: 1 } + - { domain: "com.apple.gamed", key: "Disabled", type: bool, value: 1 } # touchpad configuration - - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", bool: true } + - { domain: "com.apple.AppleMultitouchTrackpad", key: "Clicking", type: bool, value: 1 } # menu clock configuration - - { domain: "com.apple.menuextra.clock", key: "DateFormat", string: "EEE\\ d\\ MMM\\ 'at'\\ HH:mm:ss" } - - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", int: 0 } - - { domain: "com.apple.menuextra.clock", key: "Show24Hour", int: 1 } - - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", int: 1 } - - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", int: 1 } # requires restart of ??? + - { domain: "com.apple.menuextra.clock", key: "DateFormat", type: string, value: "EEE d MMM 'at' HH:mm:ss" } + - { domain: "com.apple.menuextra.clock", key: "ShowDayOfWeek", type: int, value: 0 } + - { domain: "com.apple.menuextra.clock", key: "Show24Hour", type: int, value: 1 } + - { domain: "com.apple.menuextra.clock", key: "ShowSeconds", type: int, value: 1 } + - { domain: "com.apple.controlcenter", key: "NSStatusItem\\ Visible\\ Bluetooth", type: int, value: 1 } # requires restart of ??? # domain = com.apple.finder finder: - - { key: "FXPreferredViewStyle", string: "Nlsv" } + - { key: "FXPreferredViewStyle", type: string, value: "Nlsv" } # domain = com.apple.dock dock: - - { key: "magnification", bool: true } - - { key: "tilesize", int: 32 } - - { key: "largesize", int: 128 } - - { key: "autohide", bool: true } - - { key: "showhidden", bool: true } - - { key: "wvous-tl-corner", int: 5 } - - { key: "wvous-tl-modifier", int: 0 } - - { key: "wvous-tr-corner", int: 11 } - - { key: "wvous-tr-modifier", int: 0 } - - { key: "wvous-bl-corner", int: 3 } - - { key: "wvous-bl-modifier", int: 0 } - - { key: "wvous-br-corner", int: 2 } - - { key: "wvous-br-modifier", int: 0 } - - { key: "expose-animation-duration", float: 0.5 } + - { key: "magnification", type: bool, value: 1 } + - { key: "tilesize", type: int, value: 32 } + - { key: "largesize", type: int, value: 128 } + - { key: "autohide", type: bool, value: 1 } + - { key: "showhidden", type: bool, value: 1 } + - { key: "wvous-tl-corner", type: int, value: 5 } + - { key: "wvous-tl-modifier", type: int, value: 0 } + - { key: "wvous-tr-corner", type: int, value: 11 } + - { key: "wvous-tr-modifier", type: int, value: 0 } + - { key: "wvous-bl-corner", type: int, value: 3 } + - { key: "wvous-bl-modifier", type: int, value: 0 } + - { key: "wvous-br-corner", type: int, value: 2 } + - { key: "wvous-br-modifier", type: int, value: 0 } + - { key: "expose-animation-duration", type: float, value: 0.5 } ## user files and templates: # overwrite: replace file on target, if it exists diff --git a/host_vars/localhost-standardapps.yml b/host_vars/localhost-standardapps.yml index b975787..f4028d5 100644 --- a/host_vars/localhost-standardapps.yml +++ b/host_vars/localhost-standardapps.yml @@ -25,36 +25,37 @@ system: # - { key: "AdminHostInfo", value: "HostName" } # - { key: "GuestEnabled", value: "0" } generic: -# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", string: "HostName" } -# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", bool: false } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", type: string, value: "HostName" } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", type: bool, value: 0 } ## user configuration (must be run per user) config: # domain = NSGlobalDomain global: -# - { key: "InitialKeyRepeat", int: 15 } -# - { key: "KeyRepeat", int: 1 } +# - { key: "InitialKeyRepeat", type: int, value: 15 } +# - { key: "KeyRepeat", type: int, value: 1 } generic: -# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", bool: true } +# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", type: bool, value: 1 } # domain = com.apple.finder finder: # available views: `icnv`, `clmv`, `Flwv`, `Nlsv` - - { key: "FXPreferredViewStyle", string: "Nlsv" } + - { key: "FXPreferredViewStyle", type: string, value: "Nlsv" } # domain = com.apple.dock dock: # https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356 -# - { key: "magnification", int: 1 } -# - { key: "tilesize", int: 32 } -# - { key: "largesize", int: 128 } -# - { key: "autohide", int: 1 } -# - { key: "wvous-tl-corner", int: 5 } -# - { key: "wvous-tl-modifier", int: 0 } -# - { key: "wvous-tr-corner", int: 11 } -# - { key: "wvous-tr-modifier", int: 0 } -# - { key: "wvous-bl-corner", int: 3 } -# - { key: "wvous-bl-modifier", int: 0 } -# - { key: "wvous-br-corner", int: 2 } -# - { key: "wvous-br-modifier", int: 0 } +# - { key: "magnification", type: int, value: 1 } +# - { key: "tilesize", type: int, value: 32 } +# - { key: "largesize", type: int, value: 128 } +# - { key: "autohide", type: int, value: 1 } + # hot corners: tl = top-left, br = bottom-right +# - { key: "wvous-tl-corner", type: int, value: 5 } +# - { key: "wvous-tl-modifier", type: int, value: 0 } +# - { key: "wvous-tr-corner", type: int, value: 11 } +# - { key: "wvous-tr-modifier", type: int, value: 0 } +# - { key: "wvous-bl-corner", type: int, value: 3 } +# - { key: "wvous-bl-modifier", type: int, value: 0 } +# - { key: "wvous-br-corner", type: int, value: 2 } +# - { key: "wvous-br-modifier", type: int, value: 0 } ## user files and templates: # overwrite: replace file on target, if it exists diff --git a/macdev.yml b/macdev.yml index a7d4712..19be153 100644 --- a/macdev.yml +++ b/macdev.yml @@ -29,6 +29,7 @@ become: yes become_user: root register: sudo_check + changed_when: false ignore_errors: true when: role_sys - debug: msg="Run 'sudo echo' to fix this." diff --git a/roles/ansible/tasks/main.yml b/roles/ansible/tasks/main.yml index 73a8244..cab79bf 100644 --- a/roles/ansible/tasks/main.yml +++ b/roles/ansible/tasks/main.yml @@ -3,16 +3,22 @@ - name: Add ansible collections shell: ansible-galaxy collection install {{ item.name }} --upgrade with_items: "{{ ansible_collections }}" + register: ansible_collection when: (item.version is not defined or item.version == "") and (item.source is not defined or item.source == "") + changed_when: ansible_collection.stdout | regex_search('was installed successfully') - name: Add ansible collections with version shell: ansible-galaxy collection install '{{ item.name }}:{{ item.version }}' --upgrade with_items: "{{ ansible_collections }}" + register: ansible_collection when: item.version is defined and item.version != "" and (item.source is not defined or item.source == "") + changed_when: ansible_collection.stdout | regex_search('was installed successfully') - name: Add ansible collections from source shell: ansible-galaxy collection install '{{ item.source }}' --upgrade with_items: "{{ ansible_collections }}" + register: ansible_collection when: item.source is defined and item.source != "" + changed_when: ansible_collection.stdout | regex_search('was installed successfully') diff --git a/roles/config/tasks/main.yml b/roles/config/tasks/main.yml index cb1dedb..164e049 100644 --- a/roles/config/tasks/main.yml +++ b/roles/config/tasks/main.yml @@ -5,36 +5,39 @@ - name: Global configuration shell: | - defaults write NSGlobalDomain {{ item.key }} \ - {{ "-int "+item.int|string if item.int is defined }} \ - {{ "-float "+item.float|string if item.float is defined }} \ - {{ "-bool "+item.bool|string if item.bool is defined }} \ - {{ "-string "+item.string if item.string is defined }} + curr=$(defaults read NSGlobalDomain {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write NSGlobalDomain {{ item.key }} -{{ item.type }} {{ item.value }} + echo "done" + fi with_items: "{{ config.global }}" register: global_config when: config.global is defined + changed_when: global_config.stdout == "done" - name: Generic configuration shell: | - defaults write {{ item.domain }} {{ item.key }} \ - {{ "-int "+item.int|string if item.int is defined }} \ - {{ "-float "+item.float|string if item.float is defined }} \ - {{ "-bool "+item.bool|string if item.bool is defined }} \ - {{ "-string "+item.string if item.string is defined }} + curr=$(defaults read {{ item.domain }} {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write {{ item.domain }} {{ item.key }} -{{ item.type }} "{{ item.value }}" + echo "done" + fi with_items: "{{ config.generic }}" register: generic_config when: config.generic is defined and item.domain is defined + changed_when: generic_config.stdout == "done" - name: Configure Finder shell: | - defaults write com.apple.finder {{ item.key }} \ - {{ "-int "+item.int|string if item.int is defined }} \ - {{ "-float "+item.float|string if item.float is defined }} \ - {{ "-bool "+item.bool|string if item.bool is defined }} \ - {{ "-string "+item.string if item.string is defined }} + curr=$(defaults read com.apple.finder {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write com.apple.finder {{ item.key }} -{{ item.type }} {{ item.value }} + echo "done" + fi with_items: "{{ config.finder }}" register: finder_config when: config.finder is defined + changed_when: finder_config.stdout == "done" - name: Restart Finder shell: killall Finder @@ -42,14 +45,15 @@ - name: Configure Dock shell: | - defaults write com.apple.dock {{ item.key }} \ - {{ "-int "+item.int|string if item.int is defined }} \ - {{ "-float "+item.float|string if item.float is defined }} \ - {{ "-bool "+item.bool|string if item.bool is defined }} \ - {{ "-string "+item.string if item.string is defined }} + curr=$(defaults read com.apple.dock {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write com.apple.dock {{ item.key }} -{{ item.type }} {{ item.value }} + echo "done" + fi with_items: "{{ config.dock }}" register: dock_config when: config.dock is defined + changed_when: dock_config.stdout == "done" - name: Restart Dock shell: killall Dock diff --git a/roles/system/tasks/main.yml b/roles/system/tasks/main.yml index 79b5c6d..1b7959f 100644 --- a/roles/system/tasks/main.yml +++ b/roles/system/tasks/main.yml @@ -2,42 +2,62 @@ - name: Set hostname shell: | - systemsetup -setcomputername {{ system.hostname }}; - scutil --set ComputerName {{ system.hostname }}; - scutil --set HostName {{ system.hostname }} - scutil --set LocalHostName {{ system.hostname }} - defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string {{ system.hostname|lower }} + if [ "$(scutil --get HostName)" != "{{ system.hostname }}" ]; then + systemsetup -setcomputername {{ system.hostname }}; + scutil --set ComputerName {{ system.hostname }}; + scutil --set HostName {{ system.hostname }}; + scutil --set LocalHostName {{ system.hostname }}; + defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string {{ system.hostname|lower }}; + echo "done" + fi become: yes become_user: "root" + register: set_hostname when: system.hostname is defined + changed_when: set_hostname.stdout == "done" - name: System Setup shell: | - systemsetup {{ item.key }} {{ item.value }} + key={{ item.key }} + curr=$(systemsetup ${key/set/get} | awk -F: '{print $2}' | xargs | tr '[:upper:]' '[:lower:]'); + if [ "$curr" != "{{ item.value }}" ]; then + systemsetup {{ item.key }} {{ item.value }}; + echo "done" + fi with_items: "{{ system.systemsetup }}" become: yes become_user: "root" + register: system_setup when: system.systemsetup is defined + changed_when: system_setup.stdout == "done" - name: Generic configuration shell: | - defaults write {{ item.domain }} {{ item.key }} \ - {{ "-int "+item.int|string if item.int is defined }} \ - {{ "-float "+item.float|string if item.float is defined }} \ - {{ "-bool "+item.bool|string if item.bool is defined }} \ - {{ "-string "+item.string if item.string is defined }} + curr=$(defaults read {{ item.domain }} {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write {{ item.domain }} {{ item.key }} -{{ item.type }} {{ item.value }} + echo "done" + fi with_items: "{{ system.generic }}" become: yes become_user: "root" register: generic_config when: system.generic is defined and item.domain is defined + changed_when: generic_config.stdout == "done" - name: Configure Login Window - shell: defaults write /Library/Preferences/com.apple.loginwindow {{ item.key }} {{ item.value }} + shell: | + curr=$(defaults read /Library/Preferences/com.apple.loginwindow {{ item.key }}) + if [ "$curr" != "{{ item.value }}" ]; then + defaults write /Library/Preferences/com.apple.loginwindow {{ item.key }} {{ item.value }} + echo "done" + fi with_items: "{{ system.loginwindow }}" become: yes become_user: "root" + register: login_window when: system.loginwindow is defined + changed_when: login_window.stdout == "done" - include: timemachine.yml when: system.timemachine is defined \ No newline at end of file diff --git a/roles/system/tasks/timemachine.yml b/roles/system/tasks/timemachine.yml index e83a5b0..18c50dd 100644 --- a/roles/system/tasks/timemachine.yml +++ b/roles/system/tasks/timemachine.yml @@ -7,6 +7,7 @@ become_user: "root" register: timemachine_destination when: system.timemachine.destination is defined + changed_when: false - name: Configure TimeMachine destination shell: > From 063d606dad39cf84cede56f66da5715c9dbd5bf4 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 3 Oct 2022 13:40:02 +0200 Subject: [PATCH 48/51] fix: cleanup brew packages and sort alphabetically --- host_vars/localhost-drpsychick-neo.yml | 115 ++++++++++++++----------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/host_vars/localhost-drpsychick-neo.yml b/host_vars/localhost-drpsychick-neo.yml index 5d150c2..970b0d6 100644 --- a/host_vars/localhost-drpsychick-neo.yml +++ b/host_vars/localhost-drpsychick-neo.yml @@ -88,6 +88,7 @@ templates: - { name: "gitconfig", path: "$HOME/.gitconfig", overwrite: true } - { name: "gitconfig-work", path: "$HOME/.gitconfig-work", overwrite: true } - { name: "gitconfig-private", path: "$HOME/.gitconfig-private", overwrite: true } + - { name: "registry-config.json", path: "$HOME/Library/Preferences/helm/registry/config.json", overwrite: true } # instead of copying a file or template, you can define aliases one by one shell_aliases: @@ -102,78 +103,88 @@ ansible_collections: - { name: community.kubernetes } # , version: "", source: "" } brew_packages: + - { name: ansible, path: "{{brew_bin}}/ansible" } + - { name: ansible-lint, path: "{{brew_bin}}/ansible-lint" } + - { name: awscli, path: "{{ brew_bin }}/aws" } + - { name: chart-testing, path: "{{brew_bin}}/ct" } + - { name: dive, path: "{{brew_bin}}/dive" } + - { name: glances, path: "{{brew_bin}}/glances" } - { name: gnupg, path: "{{brew_bin}}/gpg" } - - { name: jq, path: "{{brew_bin}}/jq" } - - { name: watch, path: "{{brew_bin}}/watch" } - - { name: gnupg, path: "{{brew_bin}}/gpg" } - #- { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } # conflicts with Rancher Desktop - #- { name: kubectx, path: "{{brew_bin}}/kubectx" } + - { name: go, path: "{{brew_bin}}/go" } + - { name: golangci-lint, path: "{{brew_bin}}/golangci-lint" } + - { name: goreleaser, path: "{{brew_bin}}/goreleaser" } #- { name: helm, path: "{{brew_bin}}/helm" } # conflicts with Rancher Desktop - - { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" } - - { name: node, path: "{{brew_bin}}/node" } - - { name: telegraf, path: "{{brew_bin}}/telegraf" } - - { name: mtr, path: "{{brew_sbin}}/mtr" } - - { name: smartmontools, path: "{{brew_bin}}/smartctl" } - - { name: glances, path: "{{brew_bin}}/glances" } - { name: hub, path: "{{brew_bin}}/hub" } - - { name: qemu, path: "{{brew_bin}}/qemu-img" } + - { name: jq, path: "{{brew_bin}}/jq" } - { name: k3d, path: "{{brew_bin}}/k3d" } - - { name: kustomize, path: "{{brew_bin}}/kustomize" } - - { name: kubeval, path: "{{brew_bin}}/kubeval" } + #- { name: kubectx, path: "{{brew_bin}}/kubectx" } + #- { name: kubernetes-cli, path: "{{brew_bin}}/kubectl" } # conflicts with Rancher Desktop - { name: kubeseal, path: "{{brew_bin}}/kubeseal" } - - { name: pwgen, path: "{{brew_bin}}/pwgen" } - - { name: yamllint, path: "{{brew_bin}}/yamllint" } + - { name: kubeval, path: "{{brew_bin}}/kubeval" } + - { name: kustomize, path: "{{brew_bin}}/kustomize" } - { name: molecule, path: "{{brew_bin}}/molecule" } + - { name: mtr, path: "{{brew_sbin}}/mtr" } + - { name: node, path: "{{brew_bin}}/node" } + - { name: packer, path: "{{ brew_bin }}/packer" } + - { name: pinentry-mac, path: "{{brew_bin}}/pinentry-mac" } - { name: pre-commit, path: "{{brew_bin}}/pre-commit" } + - { name: pwgen, path: "{{brew_bin}}/pwgen" } + - { name: qemu, path: "{{brew_bin}}/qemu-img" } + - { name: smartmontools, path: "{{brew_bin}}/smartctl" } + - { name: telegraf, path: "{{brew_bin}}/telegraf" } + - { name: wakeonlan, path: "{{brew_bin}}/wakeonlan" } + - { name: watch, path: "{{brew_bin}}/watch" } + - { name: yamale, path: "{{brew_bin}}/yamale" } + - { name: yamllint, path: "{{brew_bin}}/yamllint" } brew_cask_packages: + - { name: 1password, path: "/Applications/1Password.app" } + #- { name: atom, path: "/Applications/Atom.app" } + - { name: curseforge, path: "/Applications/CurseForge.app" } #- { name: docker, path: /Applications/Docker.app } - - { name: iterm2, path: /Applications/iTerm.app } - - { name: google-chrome, path: /Applications/Google Chrome.app } - - { name: atom, path: /Applications/Atom.app } - - { name: slack, path: /Applications/Slack.app } - - { name: macpass, path: /Applications/MacPass.app } - - { name: zoom, path: /Applications/zoom.us.app } - #- { name: openoffice, path: /Applications/OpenOffice.app } - #- { name: libreoffice, path: "/Applications/LibreOffice.app" } - #- { name: gimp, path: /Applications/Gimp-2.10.app } - #- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } - - { name: pycharm, path: "/Applications/PyCharm.app" } - - { name: goland, path: "/Applications/GoLand.app" } - - { name: tunnelblick, path: "/Applications/Tunnelblick.app" } - - { name: spectacle, path: "/Applications/Spectacle.app" } + - { name: deepl, path: "/Applications/Deepl.app" } + - { name: discord, path: "/Applications/Discord.app" } - { name: drawio, path: "/Applications/draw.io.app" } - - { name: postman, path: "/Applications/Postman.app" } - - { name: moonlight, path: "/Applications/Moonlight.app" } + - { name: finicky, path: "/Applications/finicky.app" } + #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } + - { name: gimp, path: "/Applications/Gimp-2.10.app" } + - { name: goland, path: "/Applications/GoLand.app" } + - { name: google-chrome, path: "/Applications/Google Chrome.app" } + - { name: google-drive, path: "/Applications/Google Drive.app" } + - { name: iterm2, path: "/Applications/iTerm.app" } - { name: krita, path: "/Applications/krita.app" } - - { name: spotify, path: "/Applications/Spotify.app" } - - { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } - - { name: monitorcontrol, path: "/Applications/MonitorControl.app" } + #- { name: libreoffice, path: "/Applications/LibreOffice.app" } + - { name: macpass, path: "/Applications/MacPass.app" } - { name: macs-fan-control, path: "/Applications/Macs Fan Control.app" } - - { name: qsync-client, path: "/Applications/QSync Client.app" } - - { name: discord, path: "/Applications/Discord.app" } - - { name: google-drive, path: "/Applications/Google Drive.app" } - - { name: vlc, path: "/Applications/VLC.app" } - #- { name: virtualbox, path: "/Applications/VirtualBox.app" } - #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" } - - { name: obsidian, path: "/Applications/Obsidian.app" } - - { name: mindforger, path: "/Applications/mindforger.app" } + - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } + - { name: minecraft, path: "/Applications/Minecraft.app" } + #- { name: mindforger, path: "/Applications/mindforger.app" } + - { name: monitorcontrol, path: "/Applications/MonitorControl.app" } #- { name: moom, path: "/Applications/Moom.app" } + - { name: moonlight, path: "/Applications/Moonlight.app" } - { name: obs, path: "/Applications/OBS.app" } - { name: obs-virtualcam, path: "{{ brew_prefix }}/Caskroom/obs-virtualcam" } - #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } - - { name: finicky, path: "/Applications/finicky.app" } - - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } - - { name: utm, path: "/Applications/UTM.app" } - - { name: minecraft, path: "/Applications/Minecraft.app" } - - { name: curseforge, path: "/Applications/CurseForge.app" } + - { name: obsidian, path: "/Applications/Obsidian.app" } + #- { name: openoffice, path: /Applications/OpenOffice.app } + - { name: postman, path: "/Applications/Postman.app" } + - { name: pycharm, path: "/Applications/PyCharm.app" } + #- { name: pycharm-ce, path: "/Applications/PyCharm CE.app" } + - { name: qsync-client, path: "/Applications/QSync Client.app" } - { name: rancher, path: "/Applications/Rancher Desktop.app" } - - { name: 1password, path: "/Applications/1Password.app" } + - { name: slack, path: "/Applications/Slack.app" } + - { name: spectacle, path: "/Applications/Spectacle.app" } + - { name: spotify, path: "/Applications/Spotify.app" } + - { name: sweet-home3d, path: "/Applications/Sweet Home 3D.app" } + - { name: tunnelblick, path: "/Applications/Tunnelblick.app" } + - { name: utm, path: "/Applications/UTM.app" } + #- { name: virtualbox, path: "/Applications/VirtualBox.app" } + #- { name: virtualbox-extension-pack, path: "{{ brew_prefix }}/Caskroom/virtualbox-extension-pack/6.1.28/Oracle_VM_VirtualBox_Extension_Pack-6.1.28.vbox-extpack" } + - { name: vlc, path: "/Applications/VLC.app" } - { name: vnc-viewer, path: "/Applications/VNC Viewer.app" } - - { name: deepl, path: "/Applications/Deepl.app" } + - { name: zoom, path: "/Applications/zoom.us.app" } pip_packages: - - { name: yamale, path: "{{pip_bin}}/yamale" } +# - { name: yamale, path: "{{pip_bin}}/yamale" } # - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" } # - { name: ansible, path: "{{pip_bin}}/ansible" } # - { name: awscli, path: "{{pip_bin}}/aws" } From 75bf6b3c52b2e2bc073c4f60651dcdca8bf23e35 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 3 Oct 2022 13:48:49 +0200 Subject: [PATCH 49/51] fix: empty pip packages --- host_vars/localhost-drpsychick-neo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host_vars/localhost-drpsychick-neo.yml b/host_vars/localhost-drpsychick-neo.yml index 970b0d6..0575cdb 100644 --- a/host_vars/localhost-drpsychick-neo.yml +++ b/host_vars/localhost-drpsychick-neo.yml @@ -183,7 +183,7 @@ brew_cask_packages: - { name: vnc-viewer, path: "/Applications/VNC Viewer.app" } - { name: zoom, path: "/Applications/zoom.us.app" } -pip_packages: +pip_packages: [] # - { name: yamale, path: "{{pip_bin}}/yamale" } # - { name: kubernetes, path: "/lib/python3.9/site-packages/kubernetes" } # - { name: ansible, path: "{{pip_bin}}/ansible" } From 8c1f2d61d16faa7b863c2244eb37c2287c5fe106 Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 3 Oct 2022 14:09:26 +0200 Subject: [PATCH 50/51] fix: determine homebrew install path (#8) --- roles/env/tasks/main.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/roles/env/tasks/main.yml b/roles/env/tasks/main.yml index e6ec59b..d1264c9 100644 --- a/roles/env/tasks/main.yml +++ b/roles/env/tasks/main.yml @@ -36,6 +36,19 @@ debug: msg: "profile '{{ shell_profile }}', rc file '{{ shell_rc }}'" +- name: Determine install path + shell: > + [ -n "$HOMEBREW_PREFIX" ] && echo "$HOMEBREW_PREFIX" || echo "/usr/local" + register: homebrew_prefix + changed_when: false + +- name: Set variables for install paths + set_fact: + brew_prefix: "{{ homebrew_prefix.stdout }}" + brew_bin: "{{ homebrew_prefix.stdout }}/bin" + brew_sbin: "{{ homebrew_prefix.stdout }}/sbin" + when: homebrew_prefix.stdout != "" + - name: Load shell profile in zsh lineinfile: dest: '{{ "$HOME/" + shell_profile }}' From 66f902b398aed0e3c45daae0480a9787646ee4aa Mon Sep 17 00:00:00 2001 From: DrPsychick Date: Mon, 3 Oct 2022 14:29:35 +0200 Subject: [PATCH 51/51] fix: separate config for CI --- .travis.yml | 2 +- host_vars/localhost-M1example.yaml | 4 +- host_vars/localhost-ci.yml | 100 +++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 host_vars/localhost-ci.yml diff --git a/.travis.yml b/.travis.yml index 74a6c2c..7e97c6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ install: script: - ansible-playbook macdev.yml --syntax-check - - cp host_vars/localhost-example.yml host_vars/localhost.yml + - cp host_vars/localhost-ci.yml host_vars/localhost.yml # run the playbook - ansible-playbook macdev.yml -e brew_skip_upgrade=true # run again -> expect no change diff --git a/host_vars/localhost-M1example.yaml b/host_vars/localhost-M1example.yaml index 1ea9aa5..3b00f30 100644 --- a/host_vars/localhost-M1example.yaml +++ b/host_vars/localhost-M1example.yaml @@ -1,8 +1,9 @@ -# this is pretty much my own config for my MacBook Air M1 --- # roles role_ssh: yes +role_sys: yes +role_cfg: yes role_ansible: true role_pip: yes role_brew: yes @@ -132,4 +133,3 @@ brew_cask_packages: #- { name: qdslrdashboard, path: "/Applications/qDslrDashboard.app" } - { name: finicky, path: "/Applications/finicky.app" } - { name: microsoft-teams, path: "/Applications/Microsoft Teams.app" } - diff --git a/host_vars/localhost-ci.yml b/host_vars/localhost-ci.yml new file mode 100644 index 0000000..f7f54f6 --- /dev/null +++ b/host_vars/localhost-ci.yml @@ -0,0 +1,100 @@ +--- + +# roles +role_ssh: yes +# role_sys requires sudo +role_sys: no +role_cfg: no +role_ansible: yes +role_pip: no +role_brew: yes +role_app: no + +## system configuration (requires sudo) +system: +# # set ComputerName, HostName and NetBIOS Name +# hostname: example + # sudo systemsetup -help + systemsetup: +# - { key: "-setrestartfreeze", value: "on" } +# - { key: "-setcomputersleep", value: "10" } +# - { key: "-setdisplaysleep", value: "5" } + loginwindow: +# - { key: "AdminHostInfo", value: "HostName" } # shows host name and info on login screen +# - { key: "GuestEnabled", value: "0" } + generic: +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "AdminHostInfo", type: string, value: "HostName" } +# - { domain: "/Library/Preferences/com.apple.loginwindow", key: "GuestEnabled", type: bool, value: 0 } + timemachine: +# destination: "smb://timemachine/macbackups" +# exclusions: +# - /Users/myuser/Library/Containers/com.docker.docker + +## user configuration (must be run per user) +config: + # domain = NSGlobalDomain + global: +# - { key: "InitialKeyRepeat", type: int, value: 15 } +# - { key: "KeyRepeat", type: int, value: 1 } + generic: +# - { domain: "com.apple.desktopservices", key: "DSDontWriteNetworkStores", type: bool, value: 1 } + # domain = com.apple.finder + finder: + # available views: `icnv`, `clmv`, `Flwv`, `Nlsv` + - { key: "FXPreferredViewStyle", type: string, value: "Nlsv" } + # domain = com.apple.dock + dock: + # https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L356 +# - { key: "magnification", type: int, value: 1 } +# - { key: "tilesize", type: int, value: 32 } +# - { key: "largesize", type: int, value: 128 } +# - { key: "autohide", type: int, value: 1 } + # hot corners: tl = top-left, br = bottom-right +# - { key: "wvous-tl-corner", type: int, value: 5 } +# - { key: "wvous-tl-modifier", type: int, value: 0 } +# - { key: "wvous-tr-corner", type: int, value: 11 } +# - { key: "wvous-tr-modifier", type: int, value: 0 } +# - { key: "wvous-bl-corner", type: int, value: 3 } +# - { key: "wvous-bl-modifier", type: int, value: 0 } +# - { key: "wvous-br-corner", type: int, value: 2 } +# - { key: "wvous-br-modifier", type: int, value: 0 } + +## user files and templates: +# overwrite: replace file on target, if it exists +# source=(interactive|login): source file for "interactive" session = .bashrc/.zshrc or "login" session = .profile/.zprofile + +# files you want to copy to the target +files: +# - { name: "gitconfig-example", path: "$HOME/.gitconfig-example", overwrite: true } + +# templates you want to copy to the target +templates: +# - { name: "bashrc-example", path: "$HOME/.bashrc-example", overwrite: true } +# - { name: "bash_aliases-example", path: "$HOME/.bash_aliases-example", overwrite: true, source: "interactive" } + +# instead of copying a file or template, you can define aliases one by one +shell_aliases: + - { name: "updatemac", cmd: "(cd ~/YOUR_MACDEV_DIRECTORY; {{ 'echo \"password for sudo:\"; sudo echo;' if role_sys }} ansible-playbook macdev.yml)" } + +ansible_collections: + - { name: community.general } + # see https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#install-multiple-collections-with-a-requirements-file + #- { name: community.docker, version: "=1.9.0" } + #- { name: community.kubernetes, source: "" } + +brew_packages: + - { name: pwgen, path: "{{ brew_bin }}/pwgen" } + - { name: jq, path: "{{ brew_bin }}/jq" } + +brew_cask_packages: + - { name: iterm2, path: /Applications/iTerm.app } + +pip_packages: + - { name: yamale, path: "{{pip_bin}}/yamale" } + +# supports .zip and .dmg +app_packages: [] + # - { name: iTerm2, app: "iTerm", url: https://iterm2.com/downloads/stable/iTerm2-3_3_2.zip } # brew install iterm2 + # - { name: Atom, app: "Atom", url: https://github.com/atom/atom/releases/download/v1.40.1/atom-mac.zip } # brew install atom + # - { name: Chrome, app: "Google Chrome", url: https://dl.google.com/chrome/mac/stable/GCEA/googlechrome.dmg } # brew install google-chrome +