From 841dc7644785472898b9811ee55d03d0a5851216 Mon Sep 17 00:00:00 2001 From: N Date: Thu, 21 Feb 2019 09:53:02 +0000 Subject: [PATCH 1/4] Add cleanup state --- README.rst | 5 +++++ golang/clean.sls | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 golang/clean.sls diff --git a/README.rst b/README.rst index 0844593..dc1759c 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,11 @@ Install go! ----------------- Helpful for debugging, dumps the jinja map to a text file +``golang.clean`` +------------ +Remove go! + + Testing diff --git a/golang/clean.sls b/golang/clean.sls new file mode 100644 index 0000000..46a4f70 --- /dev/null +++ b/golang/clean.sls @@ -0,0 +1,27 @@ +{% from "golang/map.jinja" import golang with context %} + + {%- if golang.linux.altpriority > 0 %} + + {% for i in ['go', 'godoc', 'gofmt'] %} +golang|cleanup-symlink-{{ i }}: + alternatives.remove: + - name: link-{{ i }} + - path: {{ golang.base_dir }}/go/bin/{{ i }} + - onlyif: update-alternatives --get-selections |grep ^link-{{ i }} + {% endfor %} + +golang|cleanup-home-alternative: + alternatives.remove: + - name: golang-home-link + - path: {{ golang.base_dir }}/go/ + - onlyif: update-alternatives --get-selections |grep ^golang-home-link + + {%- endif %} + +golang|remove directories: + file.absent: + - names: + - /tmp/{{ golang.archive_name }} + - {{ golang.base_dir }} + - {{ golang.go_path }} + - /etc/profile.d/golang.sh From 107e3052b0bb6f3cb3b3904017109c0c45ebb319 Mon Sep 17 00:00:00 2001 From: N Date: Thu, 21 Feb 2019 10:34:40 +0000 Subject: [PATCH 2/4] Workarounds for Suse --- golang/init.sls | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/golang/init.sls b/golang/init.sls index aa67bb7..3c2dfc8 100644 --- a/golang/init.sls +++ b/golang/init.sls @@ -63,47 +63,61 @@ golang|extract-archive: # add a symlink from versioned install to point at golang:lookup:go_root golang|install-home-alternative: + {%- if grains.os_family in ('Suse',) %} + cmd.run: + - name: update-alternatives --install {{ golang.go_root }} golang-home-link {{ golang.base_dir }}/go/ {{ golang.linux.altpriority }} + {%- else %} alternatives.install: - name: golang-home-link - link: {{ golang.go_root }} - path: {{ golang.base_dir }}/go/ - priority: {{ golang.linux.altpriority }} - order: 10 + {%- endif %} - watch: - archive: golang|extract-archive + {%- if grains.os_family not in ('Suse',) %} golang|set-home-alternative: alternatives.set: - name: golang-home-link - path: {{ golang.base_dir }}/go/ - require: - alternatives: golang|install-home-alternative + {%- endif %} {% for i in ['go', 'godoc', 'gofmt'] %} #manage symlinks to /usr/bin for the three go commands golang|create-symlink-{{ i }}: + {%- if grains.os_family in ('Suse',) %} + cmd.run: + - name: update-alternatives --install /usr/bin/{{ i }} link-{{ i }} {{ golang.base_dir }}/go/bin/{{ i }} {{ golang.linux.altpriority }} + - require: + - cmd: golang|install-home-alternative + {%- else %} alternatives.install: - name: link-{{ i }} - link: /usr/bin/{{ i }} - path: {{ golang.base_dir }}/go/bin/{{ i }} - priority: {{ golang.linux.altpriority }} - order: 10 - - watch: - - archive: golang|extract-archive - require: - alternatives: golang|install-home-alternative - - alternatives: golang|set-home-alternative + {%- endif %} + - watch: + - archive: golang|extract-archive + {%- if grains.os_family not in ('Suse',) %} golang|set-symlink={{ i }}: alternatives.set: - name: link-{{ i }} - path: {{ golang.base_dir }}/go/bin/{{ i }} - require: - alternatives: golang|create-symlink-{{ i }} + {%- endif %} {% endfor %} - {%- endif %} # sets up the necessary environment variables required for golang usage From f62d2765d4b46dcfa69a11231afdc2741dbb89cf Mon Sep 17 00:00:00 2001 From: N Date: Mon, 15 Apr 2019 00:53:35 +0100 Subject: [PATCH 3/4] Always retry alternatives.install state --- golang/init.sls | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/golang/init.sls b/golang/init.sls index 3c2dfc8..9b1addf 100644 --- a/golang/init.sls +++ b/golang/init.sls @@ -63,61 +63,53 @@ golang|extract-archive: # add a symlink from versioned install to point at golang:lookup:go_root golang|install-home-alternative: - {%- if grains.os_family in ('Suse',) %} - cmd.run: - - name: update-alternatives --install {{ golang.go_root }} golang-home-link {{ golang.base_dir }}/go/ {{ golang.linux.altpriority }} - {%- else %} alternatives.install: - name: golang-home-link - link: {{ golang.go_root }} - path: {{ golang.base_dir }}/go/ - priority: {{ golang.linux.altpriority }} - order: 10 - {%- endif %} - watch: - archive: golang|extract-archive + - retry: + attempts: 2 + until: True - {%- if grains.os_family not in ('Suse',) %} golang|set-home-alternative: alternatives.set: - name: golang-home-link - path: {{ golang.base_dir }}/go/ - require: - alternatives: golang|install-home-alternative - {%- endif %} {% for i in ['go', 'godoc', 'gofmt'] %} #manage symlinks to /usr/bin for the three go commands golang|create-symlink-{{ i }}: - {%- if grains.os_family in ('Suse',) %} - cmd.run: - - name: update-alternatives --install /usr/bin/{{ i }} link-{{ i }} {{ golang.base_dir }}/go/bin/{{ i }} {{ golang.linux.altpriority }} - - require: - - cmd: golang|install-home-alternative - {%- else %} alternatives.install: - name: link-{{ i }} - link: /usr/bin/{{ i }} - path: {{ golang.base_dir }}/go/bin/{{ i }} - priority: {{ golang.linux.altpriority }} - order: 10 - - require: - - alternatives: golang|install-home-alternative - {%- endif %} - watch: - archive: golang|extract-archive + - require: + - alternatives: golang|install-home-alternative + - alternatives: golang|set-home-alternative + - retry: + attempts: 2 + until: True - {%- if grains.os_family not in ('Suse',) %} golang|set-symlink={{ i }}: alternatives.set: - name: link-{{ i }} - path: {{ golang.base_dir }}/go/bin/{{ i }} - require: - alternatives: golang|create-symlink-{{ i }} - {%- endif %} {% endfor %} + {%- endif %} # sets up the necessary environment variables required for golang usage From 3f287181accea676e7356c88e747543f3295a740 Mon Sep 17 00:00:00 2001 From: N Date: Mon, 15 Apr 2019 01:05:35 +0100 Subject: [PATCH 4/4] Fix typo --- golang/init.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/init.sls b/golang/init.sls index ed0ffcf..7e1b8d6 100644 --- a/golang/init.sls +++ b/golang/init.sls @@ -93,7 +93,7 @@ golang|create-symlink-{{ i }}: - priority: {{ golang.linux.altpriority }} - order: 10 - require: - - alternatives: golang|install-home-alternativ + - alternatives: golang|install-home-alternative - watch: - archive: golang|extract-archive - retry: