diff --git a/.travis.yml b/.travis.yml index f1d590b..722c31d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,28 @@ --- -dist: trusty -sudo: required +language: generic matrix: fast_finish: true + include: + - os: linux + env: IMAGE=centos7 + dist: trusty + services: + - docker + - os: linux + env: IMAGE=loki + dist: trusty + services: + - docker + - os: linux + env: IMAGE=xenial + dist: trusty + services: + - docker + - os: osx + sudo: required -services: - - docker - -env: - matrix: # each entry is its own run - - IMAGE: centos7 - - IMAGE: xenial - +install: make install script: make clean test notifications: diff --git a/Makefile b/Makefile index 464b5e1..aa49173 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,66 @@ #!/usr/bin/make -f -ROLE_NAME:=go-dev - .DEFAULT_GOAL := apply .PHONY: apply DEFAULT_IMAGE:=centos7 IMAGE:=$(shell echo "$${IMAGE:-$(DEFAULT_IMAGE)}") -clean: +OS:=$(shell uname | tr '[:upper:]' '[:lower:]') + +# LINUX ONLY ------------------------------------------------------------------ +ifeq ($(OS),linux) +clean-linux: @docker-compose rm -fs $(IMAGE) -start: +start-linux: @docker-compose up -d $(IMAGE) -shell: start - @docker exec -it $(IMAGE) bash - -test: start +test-linux: start @docker exec $(IMAGE) ansible --version @docker exec $(IMAGE) wait-for-boot @docker exec $(IMAGE) ansible-galaxy install -r /etc/ansible/roles/default/tests/requirements.yml @docker exec $(IMAGE) env ANSIBLE_FORCE_COLOR=yes \ ansible-playbook /etc/ansible/roles/default/tests/playbook.yml -apply: - @mkdir -p target/ .ansible/galaxy-roles - @rsync --delete --exclude=.ansible/galaxy-roles -a ./ .ansible/galaxy-roles/$(ROLE_NAME)/ - @ansible-galaxy install -p .ansible/galaxy-roles -r requirements.yml - @ansible-playbook -i localhost, --ask-become-pass local.yml +install-linux: + @true + +install: install-linux +clean: clean-linux +start: start-linux +test: test-linux + +shell: start + @docker exec -it $(IMAGE) bash +endif + +# OSX ONLY -------------------------------------------------------------------- +ifeq ($(OS),darwin) +clean-osx: + @true + +start-osx: + @true + +test-osx: start + @mkdir -p .ansible/galaxy-roles + @rsync --delete --exclude=.ansible/galaxy-roles -a ./ .ansible/galaxy-roles/default/ + @ansible-galaxy install -p .ansible/galaxy-roles -r tests/requirements.yml + @ansible-playbook -c local -i 127.0.0.1, -e test_user=$(shell whoami) --ask-become-pass tests/playbook.yml + +install-osx: + @brew install python@2 >/dev/null + @brew link --overwrite python >/dev/null + @brew install ansible >/dev/null + @echo "Dumping Debug Information..." + @echo "Python Version: $$(python --version)" + @echo "pip Version: $$(pip --version)" + @echo "Ansible Version: $$(ansible --version)" + +install: install-osx + +clean: clean-osx +start: start-osx +test: test-osx +endif diff --git a/README.md b/README.md index 0a31cc8..8672068 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Available on Ansible Galaxy at [`naftulikay.go-dev`][galaxy]. ## Requirements -Currently only Linux and the amd64 architecture are supported, contributions welcome. +Supporting (under test) Ubuntu 16.04, elementary OS Loki, CentOS, and OSX. Only amd64 architecture is supported +for now. Other Unix-like environments may work but are not under test. ## Role Variables diff --git a/docker-compose.yml b/docker-compose.yml index d69e4be..8093c6f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,4 +47,4 @@ services: - /sys/fs/cgroup:/sys/fs/cgroup:ro - ./:/etc/ansible/roles/default:ro - ./tests/ansible.cfg:/etc/ansible/ansible.cfg:ro - stop_grace_period: 1s \ No newline at end of file + stop_grace_period: 1s diff --git a/meta/main.yml b/meta/main.yml index e07a5aa..a268a03 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -15,6 +15,7 @@ galaxy_info: versions: - trusty - xenial + - name: MacOSX galaxy_tags: - go diff --git a/tasks/discover/go.yml b/tasks/discover/go.yml deleted file mode 100644 index b4afa0f..0000000 --- a/tasks/discover/go.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: get go user details - command: getent passwd {{ go_user }} - become: true - become_user: "{{ go_user }}" - changed_when: false - register: go_user_check - -- name: set go user home - set_fact: go_user_home="{{ go_user_check.stdout_lines[0].split(':')[5] }}" diff --git a/tasks/discover/os.yml b/tasks/discover/os.yml deleted file mode 100644 index 0202152..0000000 --- a/tasks/discover/os.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: establish operating system - set_fact: - os_name: |- - {% if ansible_distribution|lower in ("redhat", "centos") -%} - redhat - {%- else -%} - {{ ansible_distribution|lower }} - {%- endif %} -- name: establish operating system release - set_fact: - os_release: |- - {% if os_name == "redhat" -%} - rhel{{ ansible_distribution_major_version }} - {%- else -%} - {{ ansible_distribution_release | lower }} - {%- endif %} diff --git a/tasks/main.yml b/tasks/main.yml index 8b458e5..9f67ac1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,11 +3,18 @@ fail: msg="go_user must be set." when: go_user is not defined -- name: discover os facts - include_tasks: discover/os.yml +- name: get go user details + command: sh -c 'echo $HOME' + become: true + become_user: "{{ go_user }}" + become_flags: -Hi + changed_when: false + register: go_user_check + vars: + ansible_ssh_pipelining: "{{ is_macos }}" -- name: discover go facts - include_tasks: discover/go.yml +- name: set go user home + set_fact: go_user_home="{{ go_user_check.stdout_lines[0] }}" - name: include system tasks include_tasks: system.yml diff --git a/tasks/system.yml b/tasks/system.yml index e578d31..1b75f72 100644 --- a/tasks/system.yml +++ b/tasks/system.yml @@ -6,11 +6,34 @@ - name: update apt cache apt: update_cache=true cache_valid_time=3600 become: true - when: os_name == "ubuntu" + when: is_ubuntu_derivative + +- name: fix homebrew ownership + command: find /usr/local -mindepth 1 -maxdepth 1 -type d -exec chown -R {{ go_user }}:admin {} \; + become: true + when: is_macos - name: install git package: name=git state=present become: true + become_user: |- + {%- if is_linux -%} + root + {%- else -%} + {{ go_user }} + {%- endif -%} + become_flags: -Hi + vars: + ansible_ssh_pipelining: "{{ is_macos }}" + +- name: install GNU tar + package: name=gnu-tar state=present + become: true + become_user: "{{ go_user }}" + become_flags: -Hi + when: is_macos + vars: + ansible_ssh_pipelining: "{{ is_macos }}" - name: download unarchive: @@ -28,7 +51,12 @@ dest: "{{ go_goroot_dir }}" mode: "0755" owner: root - group: root + group: |- + {%- if is_macos -%} + admin + {%- else -%} + root + {%- endif -%} become: true - name: configure environment @@ -36,6 +64,11 @@ src: go-profile.d.sh.j2 dest: /etc/profile.d/go.sh owner: root - group: root + group: |- + {%- if is_macos -%} + admin + {%- else -%} + root + {%- endif -%} mode: 0755 become: true diff --git a/tasks/user.yml b/tasks/user.yml index 0846645..c8691ef 100644 --- a/tasks/user.yml +++ b/tasks/user.yml @@ -5,7 +5,12 @@ state: directory mode: 0700 owner: "{{ go_user }}" - group: "{{ go_user }}" + group: |- + {%- if is_macos -%} + primarygroup + {%- else -%} + {{ go_user }} + {%- endif -%} recurse: true - name: detect dep current version @@ -53,7 +58,12 @@ url: https://github.com/golang/dep/releases/download/v{{ godep_target_version }}/dep-linux-amd64 dest: "{{ go_user_path.replace('$HOME', go_user_home) }}/bin/dep" owner: "{{ go_user }}" - group: "{{ go_user }}" + group: |- + {%- if is_macos -%} + primarygroup + {%- else -%} + {{ go_user }} + {%- endif -%} mode: 0755 force: true become: true diff --git a/tests/goss.d/commands.yml b/tests/goss.d/commands.yml index f6c53fa..3183882 100644 --- a/tests/goss.d/commands.yml +++ b/tests/goss.d/commands.yml @@ -10,3 +10,6 @@ command: exit-status: 0 stdout: - "{{.Env.go_version}}" + + 'which fuckyou': + exit-status: 0 diff --git a/tests/goss.d/files.yml b/tests/goss.d/files.yml index 4239d49..f502fa6 100644 --- a/tests/goss.d/files.yml +++ b/tests/goss.d/files.yml @@ -15,4 +15,4 @@ file: owner: root group: root filetype: symlink - linked-to: /usr/local/go-1.8.3 + linked-to: /usr/local/go-{{.Env.go_version}} diff --git a/tests/playbook.yml b/tests/playbook.yml index 013f19a..fe6dcdd 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,18 +1,17 @@ --- - name: setup hosts: localhost - vars: - container_user: vagrant + become: true tasks: - name: create user - user: name={{ container_user }} comment="Container User" shell=/bin/bash state=present + user: name={{ test_user | default('vagrant') }} comment="Container User" shell=/bin/bash state=present - name: build hosts: localhost roles: - role: default - go_version: 1.8.3 - go_user: vagrant + go_version: 1.10.3 + go_user: "{{ test_user | default('vagrant') }}" - name: test hosts: localhost @@ -24,6 +23,6 @@ goss_file: goss.yml goss_addtl_dirs: [goss.d] goss_env_vars: - go_version: 1.8.3 - go_user: vagrant + go_version: 1.10.3 + go_user: "{{ test_user | default('vagrant') }}" go_goroot_dir: /usr/local/go