--- - name: "Check installed go versions" ansible.builtin.command: cmd: "/usr/local/go/bin/go version" register: go_installed_version changed_when: false failed_when: false - name: "Install go" when: go_version not in go_installed_version.stdout block: - name: "Set go facts" ansible.builtin.set_fact: go_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'arm64' }}" go_platform: "{{ ansible_system | lower }}" - name: "Download Go" ansible.builtin.get_url: url: "https://dl.google.com/go/go{{ go_version }}.{{ go_platform }}-{{ go_arch }}.tar.gz" dest: "/tmp/go.tar.gz" mode: "0644" - name: "Unarchive Go" become: true ansible.builtin.unarchive: src: "/tmp/go.tar.gz" dest: "/usr/local" remote_src: true - name: "Add Go to shell profile" ansible.builtin.blockinfile: path: "{{ ansible_env.HOME }}/.bashrc" state: "present" prepend_newline: true append_newline: true marker: "# ==== {mark} ANSIBLE GO CONFIG" block: | if command -v go 1>/dev/null 2>&1; then export PATH="$PATH:/usr/local/go/bin" export PATH="$HOME/go/bin:$PATH" fi