Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Method to pull latest goss release, not hard-coded release #14

Open
Halfwalker opened this issue Mar 2, 2021 · 1 comment
Open

Method to pull latest goss release, not hard-coded release #14

Halfwalker opened this issue Mar 2, 2021 · 1 comment

Comments

@Halfwalker
Copy link

Right now the goss release to be pulled in the verify.yml is hard-coded to 0.3.16

molecule_goss/cookiecutter/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/verify.yml

---                                                                                                                                                                           
{% raw -%}                                                                                                                                                                    
- name: Verify                                                                                                                                                                
  hosts: all                                                                                                                                                                  
  become: true                                                                                                                                                                
  vars:                                                                                                                                                                       
    goss_version: v0.3.16                                                                                                                                                     
    goss_arch: amd64                                                                                                                                                          
    goss_bin: /usr/local/bin/goss                                                                                                                                             
    goss_sha256sum: 827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb.                                                                                         
    goss_test_directory: /tmp/molecule/goss                                                                                                                                   
    goss_format: documentation                                                                                                                                                
    goss_vars: "{{ goss_test_directory }}/vars"                                                                                                                               
    copy_defaults_vars: false                                                                                                                                                 
  tasks:                                                                                                                                                                      
    - name: Download and install Goss                                                                                                                                         
      get_url:                                                                                                                                                                
        url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"                                                             
        dest: "{{ goss_bin }}"                                                                                                                                                
        checksum: "sha256:{{ goss_sha256sum }}"                                                                                                                               
        mode: 0755                                                                                                                                                            

A cleaner method would be to find the latest release from the goss repo and pull that down. For example, this is a method I use a lot in my ansible stuff

# https://github.com/aelsabbahy/goss/releases/download/v0.3.16/goss-linux-amd64
# https://github.com/aelsabbahy/goss/releases/download/v0.3.16/goss-linux-amd64.sha256

- name: Get latest release
  uri:
    url: "https://api.github.com/repos/aelsabbahy/goss/releases/latest"
    method: GET
    return_content: true
    status_code: 200
    body_format: json
    validate_certs: false
    user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
    password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
  register: _latest_release
  until: _latest_release.status == 200
  retries: 5

- name: "Set goss_version to {{ _latest_release.json.tag_name[1:] }}"
  set_fact:
    goss_version: "{{ _latest_release.json.tag_name[1:] }}"
  when: _latest_release is defined

# Can do some magic here to handle multiple architectures
- name: Get checksum for amd64
  set_fact:
    goss_checksum: "{{ item.split(' ')[0] }}"
  with_items:
    - "{{ lookup('url', 'https://github.com/aelsabbahy/goss/releases/download/v' + goss_version + '/goss-linux-amd64.sha256', wantlist=True) | list }}"

- name: Download and install Goss
   get_url:
     url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
     dest: "{{ goss_bin }}"
     checksum: "sha256:{{ goss_sha256sum }}"
     mode: 0755

Here's a sample run

PLAY [all] ******************************

TASK [Gathering Facts] ******************
ok: [test2.local]

TASK [Get latest release] ***************
ok: [test2.local]

TASK [Set goss_version to 0.3.16] *******
ok: [test2.local]

TASK [Get checksum for amd64] ***********
ok: [test2.local] => (item=827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb goss-linux-amd64)

TASK [debug] ****************************
ok: [test2.local] =>
goss_version: 0.3.16

TASK [debug] ****************************
ok: [test2.local] =>
goss_checksum: 827e354b48f93bce933f5efcd1f00dc82569c42a179cf2d384b040d8a80bfbfb

@abtreece
Copy link
Collaborator

abtreece commented Mar 5, 2021

Nice @Halfwalker

It seems like we should allow for specifying a version in vars, otherwise we default to latest.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants