diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..2538a3e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,48 @@ +--- +namespace: geerlingguy +name: mac +version: "1.2.0" +readme: README.md + +authors: + - geerlingguy + +description: Collection of macOS automation tools for Ansible. + +# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only +# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' +license: + - MIT + +# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character +# requirements as 'namespace' and 'name' +tags: + - mac + - macos + - tools + - osx + - homebrew + - brew + - workstation + - dev + - mas + - appstore + - apps + - configure + - development + - apple + - ios + - macbook + - imac + - macmini + - server + +dependencies: + - community.general: ">=3.0.0" + +repository: https://github.com/geerlingguy/ansible-collection-mac +documentation: https://github.com/geerlingguy/ansible-collection-mac +homepage: https://www.jeffgeerling.com +issues: https://github.com/geerlingguy/ansible-collection-mac/issues + +build_ignore: [] diff --git a/roles/homebrew/defaults/main.yml b/roles/homebrew/defaults/main.yml index 5b7d7cc..6908a16 100644 --- a/roles/homebrew/defaults/main.yml +++ b/roles/homebrew/defaults/main.yml @@ -1,8 +1,8 @@ --- homebrew_repo: https://github.com/Homebrew/brew -homebrew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}" -homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_machine != 'arm64' }}" +homebrew_prefix: "{{ (ansible_facts['machine'] == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}" +homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_facts['machine'] != 'arm64' }}" homebrew_brew_bin_path: "{{ homebrew_prefix }}/bin" homebrew_installed_packages: [] diff --git a/roles/homebrew/handlers/main.yml b/roles/homebrew/handlers/main.yml index d80e266..eb227b5 100644 --- a/roles/homebrew/handlers/main.yml +++ b/roles/homebrew/handlers/main.yml @@ -6,5 +6,5 @@ path: "{{ homebrew_cache_path.stdout | trim }}" state: absent when: 'homebrew_clear_cache | bool' - become: "{{ (homebrew_user != ansible_user_id) | bool }}" + become: "{{ (homebrew_user != ansible_facts['user_id']) | bool }}" become_user: "{{ homebrew_user }}" diff --git a/roles/homebrew/tasks/main.yml b/roles/homebrew/tasks/main.yml index 7d33b8d..5fd485e 100644 --- a/roles/homebrew/tasks/main.yml +++ b/roles/homebrew/tasks/main.yml @@ -1,8 +1,8 @@ --- - name: Determine Homebrew ownership variables set_fact: - homebrew_user: '{{ homebrew_user | default(ansible_user_id) }}' - homebrew_group: '{{ homebrew_group | default(ansible_user_gid) }}' + homebrew_user: '{{ homebrew_user | default(ansible_facts["user_id"]) }}' + homebrew_group: '{{ homebrew_group | default(ansible_facts["user_gid"]) }}' # Homebrew setup prerequisites. - name: Ensure Homebrew parent directory has correct permissions (Apple Silicon). @@ -11,10 +11,10 @@ owner: "{{ homebrew_user }}" state: directory become: true - when: ansible_machine == 'arm64' + when: ansible_facts["machine"] == 'arm64' - name: Ensure Homebrew parent directory has correct permissions (Intel). - when: ansible_machine == 'x86_64' + when: ansible_facts["machine"] == 'x86_64' block: - name: Ensure Homebrew parent directory has correct permissions (MacOS >= 10.13). file: @@ -22,7 +22,7 @@ owner: root state: directory become: true - when: "ansible_distribution_version is version('10.13', '>=')" + when: "ansible_facts['distribution_version'] is version('10.13', '>=')" - name: Ensure Homebrew parent directory has correct permissions (MacOS < 10.13). file: @@ -32,7 +32,7 @@ state: directory mode: "0775" become: true - when: "ansible_distribution_version is version('10.13', '<')" + when: "ansible_facts['distribution_version'] is version('10.13', '<')" - name: Check if homebrew already exists. stat: @@ -98,7 +98,7 @@ - name: Add missing folder if not on Apple-chipset set_fact: homebrew_folders_base: "{{ homebrew_folders_base + ['Homebrew'] }}" - when: ansible_machine != 'arm64' + when: ansible_facts["machine"] != 'arm64' - name: Ensure proper homebrew folders are in place. file: @@ -111,12 +111,12 @@ - name: Collect package manager fact. setup: - filter: ansible_pkg_mgr + filter: ansible_facts["pkg_mgr"] - name: Perform brew installation. # Privilege escalation is only required for inner steps when # the `homebrew_user` doesn't match the `ansible_user_id` - become: "{{ (homebrew_user != ansible_user_id) | bool }}" + become: "{{ (homebrew_user != ansible_facts['user_id']) | bool }}" become_user: "{{ homebrew_user }}" block: - name: Force update brew after installation. @@ -142,7 +142,7 @@ homebrew_cask: name: "{{ item }}" state: absent - sudo_password: "{{ ansible_become_password | default(omit) }}" + sudo_password: "{{ ansible_facts['become_password'] | default(omit) }}" loop: "{{ homebrew_cask_uninstalled_apps }}" - name: Install configured cask applications. @@ -151,7 +151,7 @@ state: present install_options: "{{ item.install_options | default('appdir=' + homebrew_cask_appdir) }}" accept_external_apps: "{{ homebrew_cask_accept_external_apps }}" - sudo_password: "{{ ansible_become_password | default(omit) }}" + sudo_password: "{{ ansible_facts['become_password'] | default(omit) }}" loop: "{{ homebrew_cask_apps }}" notify: - Clear homebrew cache diff --git a/roles/mas/defaults/main.yml b/roles/mas/defaults/main.yml index 3156151..2e88a75 100644 --- a/roles/mas/defaults/main.yml +++ b/roles/mas/defaults/main.yml @@ -10,4 +10,4 @@ mas_installed_apps: - { id: 497799835, name: "Xcode (8.1)" } mas_upgrade_all_apps: false mas_signin_dialog: false -mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_architecture == 'arm64' else '/usr/local/bin/mas' }}" +mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_facts['architecture'] == 'arm64' else '/usr/local/bin/mas' }}" diff --git a/roles/mas/tasks/main.yml b/roles/mas/tasks/main.yml index ff03842..a4c46f0 100644 --- a/roles/mas/tasks/main.yml +++ b/roles/mas/tasks/main.yml @@ -11,13 +11,13 @@ check_mode: false changed_when: false when: - - ansible_distribution_version is version('12', '<') + - ansible_facts["distribution_version"] is version('12', '<') - name: Sign in to MAS when email and password are provided. command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}"' register: mas_signin_result when: - - ansible_distribution_version is version('10.13', '<') + - ansible_facts["distribution_version"] is version('10.13', '<') - mas_account_result.rc == 1 - mas_email is truthy - mas_password is truthy @@ -27,7 +27,7 @@ command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}" --dialog' register: mas_signin_result when: - - ansible_distribution_version is version('10.13', '<') + - ansible_facts["distribution_version"] is version('10.13', '<') - mas_signin_dialog - mas_account_result.rc == 1 - mas_email is truthy