Skip to content

Commit

Permalink
Merge pull request #14 from toby-griffiths/mac-support-for-installing…
Browse files Browse the repository at this point in the history
…-dependencies

Adds tasks for installing dependencies on Mac
  • Loading branch information
thomvaill committed Oct 3, 2022
2 parents d5b11e9 + b24ef23 commit fc4df1d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
38 changes: 36 additions & 2 deletions ansible/install-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- hosts: localhost
tasks:
- name: Install Vagrant, Virtualbox and other dependencies
- name: Install Vagrant, Virtualbox and other dependencies (linux)
become: yes
package:
name: "{{ item }}"
Expand All @@ -16,8 +16,29 @@
- virtualbox
- vagrant
- jq
when: ansible_facts['os_family'] != "Darwin"

- name: Install Terraform
- name: Install Vagrant & Virtualbox (mac)
become: no
homebrew_cask:
name: "{{ item }}"
state: present
with_items:
- virtualbox
- vagrant
when: ansible_facts['os_family'] == "Darwin"

- name: Other dependencies (mac)
become: no
homebrew:
name: "{{ item }}"
state: present
with_items:
- coreutils # for GNU ls
- jq
when: ansible_facts['os_family'] == "Darwin"

- name: Install Terraform (linux)
shell: >
wget -O /tmp/terraform.zip "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
&& unzip -d ~/.local/bin /tmp/terraform.zip
Expand All @@ -27,6 +48,19 @@
args:
creates: ~/.local/bin/terraform
warn: False
when: ansible_facts['os_family'] != "Darwin"

- name: Install Terraform Homebrew Tap (Mac)
homebrew_tap:
name: hashicorp/tap
state: present
when: ansible_facts['os_family'] == "Darwin"

- name: Install Terraform (Mac)
homebrew:
name: hashicorp/tap/terraform
state: present
when: ansible_facts['os_family'] == "Darwin"

- hosts: localhost
tags:
Expand Down
22 changes: 14 additions & 8 deletions scripts/commands/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ main () {

echo "Installing Ansible..."
if ! command -v ansible > /dev/null; then
echo "Your SUDO password may be asked"

[[ "${TADS_VERBOSE:-}" == true ]] && set -x
sudo apt-get update \
&& sudo apt-get --yes install software-properties-common \
&& sudo apt-add-repository --yes --update ppa:ansible/ansible \
&& sudo apt-get --yes install ansible
set +x
if command -v apt-get > /dev/null; then
echo "Your SUDO password may be asked"

[[ "${TADS_VERBOSE:-}" == true ]] && set -x
sudo apt-get update \
&& sudo apt-get --yes install software-properties-common \
&& sudo apt-add-repository --yes --update ppa:ansible/ansible \
&& sudo apt-get --yes install ansible
set +x
else
echo "Unable to work out how to install Ansible. Either install it first, manually,"
echo "or update the ${SELF_PATH}/${SELF_NAME} script"
echo "to support installing automatically on your OS."
fi
else
echo "Ansible is already installed. Skipping"
fi
Expand Down
7 changes: 6 additions & 1 deletion scripts/includes/ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ readonly TADS_MIN_ANSIBLE_VERSION="2.8"
export ANSIBLE_DEPRECATION_WARNINGS="False"

get_ansible_remote_environments () {
ls -1 -I "localhost" -I "*.sample*" "${ROOT_PATH}/ansible/inventories"
# Test for Mac GNU ls command (installed in `ansible/install-dependencies.yml`)
if [ -f /usr/local/opt/coreutils/libexec/gnubin/ls ] ; then
/usr/local/opt/coreutils/libexec/gnubin/ls -1 -I "localhost" -I "*.sample*" "${ROOT_PATH}/ansible/inventories"
else
ls -1 -I "localhost" -I "*.sample*" "${ROOT_PATH}/ansible/inventories"
fi
}

check_ansible () {
Expand Down

0 comments on commit fc4df1d

Please sign in to comment.