diff --git a/defaults/main.yml b/defaults/main.yml index 578fc32..46c5343 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,6 +2,10 @@ sensu_agent: yes sensu_backend: no +sensu_build_agent: no +sensu_build_go_version: 1.7 +sensu_build_version: 5.1.1 + sensu_repository_system: '{{ ansible_distribution|lower }}' sensu_repository_release: '{{ ansible_distribution_release }}' diff --git a/tasks/build_agent.yml b/tasks/build_agent.yml new file mode 100644 index 0000000..40b6e52 --- /dev/null +++ b/tasks/build_agent.yml @@ -0,0 +1,57 @@ +--- +- name: install build dependencies + apt: + name: 'golang-{{ sensu_build_go_version }}' + tags: sensu + +- name: check if binary exist + stat: + path: /usr/local/bin/sensu-agent + register: bin + tags: sensu + +- name: download source code + git: + repo: https://github.com/sensu/sensu-go/ + version: '{{ sensu_build_version }}' + dest: /usr/local/src/sensu-go + when: git.changed or not bin.stat.exists + tags: sensu + +- name: install dependencies + command: + args: + chdir: /usr/local/src/sensu-go + argv: + - '/usr/lib/go-{{ sensu_build_go_version }}/bin/go' + - get + - ./cmd/sensu-agent/ + environment: + GOPATH: /usr/local/src/go + GOBIN: /usr/local/src/go/bin + when: git.changed or not bin.stat.exists + tags: sensu + +- name: build program + command: + args: + chdir: /usr/local/src/sensu-go + argv: + - '/usr/lib/go-{{ sensu_build_go_version }}/bin/go' + - build + - '-o' + - /usr/local/bin/sensu-agent + - main.go + environment: + GOPATH: /usr/local/src/go + GOBIN: /usr/local/src/go/bin + when: git.changed or not bin.stat.exists + tags: go + +- name: set permission on binary + file: + path: /usr/local/bin/sensu-agent + owner: root + group: root + mode: 0755 + tags: go