From 502ab9f1f22cbe22b2b4a6963d5ccc2ac8acc70b Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Thu, 17 Oct 2019 10:25:49 +0200 Subject: [PATCH] VS Code/ Languages: add golang --- README.md | 2 ++ defaults/main.yml | 2 ++ tasks/vscode-Archlinux.yml | 15 ++++++++++- tasks/vscode-Darwin.yml | 15 ++++++++++- tasks/vscode-Debian.yml | 16 +++++++++++- tasks/vscode.yml | 51 +++++++++++++++++++++++++++++++++----- 6 files changed, 92 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c1b2896..bf49cae 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ For a GUI/ Desktop machine, you can enable to install and configure VS Code: - `user_vscode`: Boolean to install and set the basic configuration of VS Code - `user_lang_cpp`: Boolean to install C/C++ dev tools and configure VS Code - `user_lang_python`: Boolean to install Python dev tools and configure VS Code +- `user_lang_golang`: Boolean to install Golang dev tools and configure VS Code +The `user_lang_*` switches will also install the language onyl, if `user_vscode` is set to false. Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 1e1783a..84d2fb2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -11,3 +11,5 @@ usersetup_gitconfig: true user_vscode: false user_lang_cpp: false user_lang_python: false +user_lang_golang: false +user_lang_golang_gopath: "{{ ansible_user_dir }}/Development/go" diff --git a/tasks/vscode-Archlinux.yml b/tasks/vscode-Archlinux.yml index d9b69e5..de59af2 100644 --- a/tasks/vscode-Archlinux.yml +++ b/tasks/vscode-Archlinux.yml @@ -24,7 +24,7 @@ - name: vscode - C/C++ - Install developer tools package: name: "{{ packages }}" - state: latest + state: present vars: packages: - clang-format @@ -33,3 +33,16 @@ # VS Code - Python Development Tools # all done in vscode.yml + + +# VS Code - Golang Development Tools +- name: vscode - Golang + block: + - name: vscode - Golang - Install developer tools + package: + name: "{{ packages }}" + state: present + vars: + packages: + - go + when: user_lang_golang == true diff --git a/tasks/vscode-Darwin.yml b/tasks/vscode-Darwin.yml index 9d891ce..38947d0 100644 --- a/tasks/vscode-Darwin.yml +++ b/tasks/vscode-Darwin.yml @@ -24,7 +24,7 @@ - name: vscode - C/C++ - Install developer tools homebrew: name: "{{ packages }}" - state: latest + state: present vars: packages: - clang-format @@ -33,3 +33,16 @@ # VS Code - Python Development Tools # all done in vscode.yml + + +# VS Code - Golang Development Tools +- name: vscode - Golang + block: + - name: vscode - Golang - Install developer tools + homebrew: + name: "{{ packages }}" + state: present + vars: + packages: + - go + when: user_lang_golang == true diff --git a/tasks/vscode-Debian.yml b/tasks/vscode-Debian.yml index 0a0aaa1..04c2577 100644 --- a/tasks/vscode-Debian.yml +++ b/tasks/vscode-Debian.yml @@ -26,7 +26,7 @@ become: yes package: name: "{{ packages }}" - state: latest + state: present vars: packages: - clang-format @@ -35,3 +35,17 @@ # VS Code - Python Development Tools # all done in vscode.yml + + +# VS Code - Golang Development Tools +- name: vscode - Golang + block: + - name: vscode - Golang - Install developer tools + become: yes + apt: + name: "{{ packages }}" + state: present + vars: + packages: + - golang + when: user_lang_golang == true diff --git a/tasks/vscode.yml b/tasks/vscode.yml index 12f2d50..c465133 100644 --- a/tasks/vscode.yml +++ b/tasks/vscode.yml @@ -9,6 +9,8 @@ # - user_vscode: Boolean, if vscode should be installed and configured # - user_lang_cpp: Boolean for C and C++ # - user_lang_python: Boolean for Python +# - user_lang_golang: Boolean for Golang +# - user_lang_golang_gopath: Go workspace directory - name: vscode - Install and configure VS Code @@ -44,12 +46,12 @@ # VS Code - Python Development Tools - - name: vscode - Python - Install python dev packages - pip: - name: - - autopep8 - - pylint - executable: /usr/local/bin/pip3 +- name: vscode - Python - Install python dev packages + pip: + name: + - autopep8 + - pylint + executable: /usr/local/bin/pip3 when: user_lang_python == true - name: vscode - Python block: @@ -58,3 +60,40 @@ PATH=/usr/local/bin:$PATH code --install-extension ms-python.python when: user_vscode == true and user_lang_python == true + + +# VC Code - Golang Development Tools +# https://golang.org/doc/install +- name: vscode - Golang - Setup Environment + block: + - name: vscode - Golang - Create workspace directory + file: + path: "{{ user_lang_golang_gopath }}" + state: directory + - name: vscode - Golang - Create zshrc-host + file: + path: "{{ ansible_user_dir}}/.zshrc-host" + state: touch + - name: vscode - Golang - Add GOPATH + lineinfile: + path: "{{ ansible_user_dir}}/.zshrc-host" + line: "export GOPATH={{ user_lang_golang_gopath }}" + state: present + backup: yes + - name: vscode - Golang - Add go bin to PATH + lineinfile: + path: "{{ ansible_user_dir}}/.zshrc-host" + line: "export PATH=$PATH:{{ user_lang_golang_gopath }}/bin" + state: present + backup: yes + # TODO: make this resilient agains changes + # and group all golang stuff in one section inside zshrc-host + when: user_lang_golang == true + +- name: vscode - Golang + block: + - name: vscode - Golang - Configure VS Code + shell: | + PATH=/usr/local/bin:$PATH + code --install-extension ms-vscode.go + when: user_vscode == true and user_lang_golang == true