-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-agent.yaml
110 lines (108 loc) · 3.4 KB
/
deploy-agent.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
- name: Deploy Agents
hosts: all
remote_user: pi
become: true
# todo: fail when these env vars are unset
vars:
OP_SERVICE_ACCOUNT_TOKEN: "{{ lookup('ansible.builtin.env', 'OP_SERVICE_ACCOUNT_TOKEN') }}"
DD_API_KEY: "{{ lookup('ansible.builtin.env', 'DD_API_KEY') }}"
OP_VERSION: "2.23.0"
tasks:
- name: Gather installed op cli version, if there is any
shell:
cmd: op --version
register: result
changed_when: false
failed_when: result.rc != 0 and result.rc != 127
- name: Set default version, if there is no
set_fact:
result:
stdout_lines: "0.0.0_000"
when: "'command not found' in result.stdout"
- name: Install or upgrade op cli
shell: |
curl -sSfo /tmp/op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/v{{ OP_VERSION }}/op_linux_arm_v{{ OP_VERSION }}.zip"
unzip -od /usr/local/bin/ /tmp/op.zip
rm /tmp/op.zip
when:
- result.stdout_lines[0] != OP_VERSION
- name: Make directory
file:
path: /usr/local/src/pi-sensor-agent/
state: directory
- name: Write 1password env file
ansible.builtin.template:
src: ./agent/deployment/op-env.j2
dest: /usr/local/src/pi-sensor-agent/.op-env
owner: root
group: root
no_log: True
register: onepass_env
- name: Copy log-forwader binary
ansible.builtin.copy:
src: ./build/agent-log-forwarder
dest: /usr/local/src/pi-sensor-agent/agent-log-forwarder
mode: '0755'
owner: root
group: root
force: yes
register: forwarder_binary
- name: Write forwarder env file
ansible.builtin.template:
src: ./log-forwarder/deployment/env-file.tmpl
dest: /usr/local/src/pi-sensor-agent/.forwarder-env-file
owner: root
group: root
force: yes
- name: Copy forwarder systemd unit file
ansible.builtin.template:
src: ./log-forwarder/deployment/systemd-unit.service.j2
dest: /etc/systemd/system/agent-log-forwarder.service
owner: root
group: root
register: forwarder_systemd
- name: Restart forwarder systemd unit
become: true
systemd:
daemon_reload: yes
enabled: yes
force: yes
name: agent-log-forwarder
state: restarted
when: forwarder_binary.changed | bool or forwarder_systemd.changed | bool or onepass_env.changed | bool
- name: Write agent op cli env-file template
ansible.builtin.template:
src: ./agent/deployment/env-file.tmpl
dest: /usr/local/src/pi-sensor-agent/.env-file.tmpl
owner: root
group: root
force: yes
- name: Copy agent systemd unit file
ansible.builtin.template:
src: ./agent/deployment/systemd-unit.service.j2
dest: /etc/systemd/system/pi-sensor-agent-{{ item.sensor_source }}.service
owner: root
group: root
with_items:
- "{{ agents }}"
register: agent_systemd
- name: Copy agent binary
ansible.builtin.copy:
src: ./build/pi-sensor-agent
dest: /usr/local/src/pi-sensor-agent/pi-sensor-agent
mode: '0755'
owner: pi
group: pi
force: yes
register: agent_binary
- name: Restart agent systemd unit
become: true
systemd:
daemon_reload: yes
enabled: yes
force: yes
name: pi-sensor-agent-{{ item.sensor_source }}
state: restarted
with_items:
- "{{ agents }}"
when: agent_binary.changed | bool or agent_systemd.changed | bool or onepass_env.changed | bool