Skip to content

Commit d423621

Browse files
author
Greg Malkov
authored
Update install script for agent version 2.x (#43)
* update install script for 2.x * fix RedHat-specific syntax * fix 1.x syntax * account for different repos * fix idempotence
1 parent ce40163 commit d423621

File tree

12 files changed

+163
-30
lines changed

12 files changed

+163
-30
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: xenial
12
language: python
23
python: '2.7'
34
sudo: required
@@ -10,13 +11,12 @@ install:
1011
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
1112
script:
1213
- ansible-playbook -v -i tests/inventory tests/test.yml --syntax-check
13-
- ansible-playbook -v -i tests/inventory tests/test.yml --connection=local --sudo
14+
- ansible-playbook -v -i tests/inventory tests/test.yml --connection=local --sudo --skip-tags "checkstate"
1415
- ansible-playbook -v -i tests/inventory tests/test.yml --check --diff --connection=local --sudo
1516
- "echo 'Sleeping 60 while agent checks in initially and creates .audit.'; sleep 60"
1617
- "ansible-playbook -v -i tests/inventory tests/test.yml --connection=local --sudo |
1718
tee /tmp/output.txt; grep -q 'changed=0.*failed=0' /tmp/output.txt && (echo 'Idempotence test: pass' && exit 0) ||
1819
(echo 'Idempotence test: fail' && exit 1)"
19-
2020
env:
2121
global:
22-
secure: "iCi7Uja9PDxhtJHBSHHxZi8Awj0b/mfdlRdIHLDx51iONQlV4YLfPn/aTx4nD8a91V0WZqg11APIjZZxW/ViuU23qwgUB4MQ80QAn2mL3jRkXzmc9gQR3OZZd9KsPHTFUAOYMbenNFSTYS/PIZykkU6PsAydIe9dZTvLOrozD3I="
22+
secure: "iCi7Uja9PDxhtJHBSHHxZi8Awj0b/mfdlRdIHLDx51iONQlV4YLfPn/aTx4nD8a91V0WZqg11APIjZZxW/ViuU23qwgUB4MQ80QAn2mL3jRkXzmc9gQR3OZZd9KsPHTFUAOYMbenNFSTYS/PIZykkU6PsAydIe9dZTvLOrozD3I="

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,29 @@ Platforms
1616
* CentOS
1717
* RedHat
1818
* Ubuntu
19+
* Debian
1920

2021
Role Variables
2122
--------------
2223
The following variables are available for override.
2324
```
2425
threatstack_deploy_key: # Required. Your Cloud Sight API Key
25-
threatstack_feature_plan: # Set value to reflect your feature plan. https://www.threatstack.com/plans
26-
# * 'agent_type="i"' - Investigate or Legacy (Basic, Advanced, Pro)
27-
# * 'agent_type="m"' - Monitor
28-
threatstack_ruleset: # The Agent's rule set, will default to "Default Rule Set".
26+
threatstack_feature_plan: # AGENT 1.x ONLY!
27+
# Required. Set value to reflect your feature plan. https://www.threatstack.com/plans
28+
# * 'agent_type="i"' - Investigate or Legacy (Basic, Advanced, Pro)
29+
# * 'agent_type="m"' - Monitor
30+
threatstack_ruleset: # Array of agent rule sets, will default to ["Base Rule Set"].
2931
# Define multiple rule sets using a comma seperated list.
3032
threatstack_pkg_url: # Location of package repo. Only change if you mirror your own.
31-
threatstack_pkg: # name of package. Specify package version using "threatstack-agent=X.Y.Z"
32-
threatstack_hostname: # The display hostname in the Threat Stack UI
33+
threatstack_pkg: # Name of package. Specify package version using
34+
# "threatstack-agent=X.Y.Z" (Debian/Ubuntu)
35+
# "threatstack-agent-X.Y.Z" (RedHat/CentOS/Amazon)
36+
# Defaults to latest available version.
37+
threatstack_url: # The URL of the Threat Stack webapp. Defaults to https://app.threatstack.com
38+
threatstack_hostname: # The display hostname in the Threat Stack UI. Defaults to hostname.
3339
threatstack_configure_agent: # Optionally do not configure the host, just install package
34-
threatstack_agent_config_args: # Pass optional configuration arguments during agent registration.
40+
threatstack_agent_extra_args: # Pass optional arguments during agent registration.
41+
threatstack_agent_config_args: # Pass optional configuration arguments after agent registration.
3542
```
3643

3744
Install

defaults/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
# defaults file for threatstack
33

4-
threatstack_pkg_url: 'https://pkg.threatstack.com'
4+
threatstack_v1_pkg_url: 'https://pkg.threatstack.com'
5+
threatstack_v2_pkg_url: 'https://pkg.threatstack.com/v2'
56
threatstack_pkg_state: installed
6-
# to set a version of the agent use threatstack-agent=X.Y.Z
7+
# to set a version of the agent use threatstack-agent=X.Y.Z (Debian) or threatstack-agent-X.Y.Z (RedHat)
78
threatstack_pkg: threatstack-agent
8-
#threatstack_hostname:
9+
threatstack_url: https://app.threatstack.com
910
threatstack_ruleset:
1011
- 'Base Rule Set'
1112
threatstack_config_dir: '/etc/threatstack'
@@ -17,4 +18,4 @@ threatstack_agent_config_args:
1718
# Set according to feature plan. https://www.threatstack.com/plans
1819
# * agent_type="i" - Investigate, Legacy (Basic, Pro, Advanced)
1920
# * agent_type="m" - Monitor
20-
agent_type: "{{ threatstack_feature_plan | mandatory }}"
21+
agent_type: "{{ threatstack_feature_plan | default('') }}"

handlers/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
- name: restart cloudsight
22
service: name=cloudsight state=restarted
3+
4+
- name: restart tsagent
5+
service: name=threatstack state=restarted

meta/main.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,29 @@ galaxy_info:
44
description: Ansible role to install the threatstack agent
55
company: Threat Stack
66
license: license (Apache)
7-
min_ansible_version: 1.3
7+
min_ansible_version: 1.6
88
platforms:
99
- name: EL
1010
versions:
1111
- all
12-
- 6
1312
- 7
1413
- name: Debian
1514
versions:
1615
- all
17-
- 7
1816
- 8
19-
- name: Fedora
20-
versions:
21-
- 25
17+
- 9
2218
- name: Amazon
2319
versions:
2420
- all
25-
- 2013.03
26-
- 2013.09
21+
- 2017.09
22+
- 2018.03
23+
- 2
2724
- name: Ubuntu
2825
versions:
2926
- all
30-
- precise
3127
- trusty
3228
- xenial
29+
- bionic
3330
categories:
3431
- cloud
3532
- cloud:ec2

tasks/cloudsight_setup.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22

3-
# Cloudsight Setup
3+
# 1.x agent setup
4+
45
- name: Create Threat Stack Config Directory
56
file:
67
path: "{{ threatstack_config_dir }}"
@@ -18,8 +19,8 @@
1819
group: root
1920
mode: 0644
2021

21-
- name: Cloudsight - setup default
22-
command: cloudsight setup --config={{ threatstack_config }} --agent_type={{ agent_type }} {{ threatstack_agent_extra_args }}
22+
- name: Agent setup
23+
command: cloudsight setup --url={{ threatstack_url }} --config={{ threatstack_config }} --agent_type={{ agent_type }} {{ threatstack_agent_extra_args }}
2324
register: setup_result
2425
args:
2526
creates: /opt/threatstack/cloudsight/config/.audit
@@ -41,7 +42,7 @@
4142
when: config_args.changed
4243
notify: restart cloudsight
4344

44-
- name: Test cloudsight state
45+
- name: Test agent state
4546
service:
4647
name: cloudsight
4748
enabled: yes

tasks/facts.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: Check if agent is v1.x
3+
set_fact:
4+
threatstack_v1_string: "{{ threatstack_pkg | regex_search('agent[=-]1\\.') }}"
5+
6+
- name: Define v1 variable
7+
set_fact:
8+
threatstack_v1: "{{ threatstack_v1_string != '' }}"
9+
10+
- name: Ensure agent_type is defined
11+
fail:
12+
msg: "threatstack_feature_plan is mandatory for 1.x agents!"
13+
when:
14+
- threatstack_v1
15+
- agent_type == ''

tasks/main.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
---
2-
# Setup tasks
2+
- name: Define some facts based on variables
3+
include: facts.yml
4+
5+
- name: Ensure package URL is defined
6+
include: pkg_url.yml
7+
when: threatstack_pkg_url is undefined
8+
39
- name: Run Apt configure and install Threat Stack
410
include: apt_install.yml
511
when: ansible_os_family == 'Debian'
@@ -8,6 +14,14 @@
814
include: yum_install.yml
915
when: ansible_os_family == 'RedHat'
1016

11-
- name: Fire cloudsight setup
17+
- name: 1.x agent setup
1218
include: cloudsight_setup.yml
13-
when: threatstack_configure_agent == true
19+
when:
20+
- threatstack_configure_agent == true
21+
- threatstack_v1
22+
23+
- name: 2.x agent setup
24+
include: tsagent_setup.yml
25+
when:
26+
- threatstack_configure_agent == true
27+
- not threatstack_v1

tasks/pkg_url.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Define v1 package URL variable
3+
set_fact:
4+
threatstack_pkg_url: "{{ threatstack_v1_pkg_url }}"
5+
when: threatstack_v1
6+
7+
- name: Define v2 package URL variable
8+
set_fact:
9+
threatstack_pkg_url: "{{ threatstack_v2_pkg_url }}"
10+
when: not threatstack_v1

tasks/tsagent_setup.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
3+
# 2.x agent setup
4+
5+
- name: Get setup string
6+
set_fact:
7+
setup_string: tsagent setup -url {{ threatstack_url }} -deploy-key {{ threatstack_deploy_key }} -ruleset "{{ threatstack_ruleset | join(",") }}" {{ threatstack_agent_extra_args }}
8+
9+
- name: Get checksum of setup string
10+
set_fact:
11+
setup_checksum: "{{ setup_string | checksum }}"
12+
13+
- name: Create file to track checksum of setup string
14+
copy:
15+
content: "{{ setup_checksum }}"
16+
dest: /opt/threatstack/etc/.setup_checksum
17+
owner: root
18+
group: root
19+
mode: 0644
20+
register: setup_file
21+
22+
- name: Get config string
23+
set_fact:
24+
config_string: tsagent config -set {{ threatstack_agent_config_args }}
25+
26+
- name: Get checksum of config string
27+
set_fact:
28+
config_checksum: "{{ config_string | checksum }}"
29+
30+
- debug:
31+
msg: "{{ threatstack_agent_config_args }}"
32+
33+
- name: Create file to track checksum of config string
34+
copy:
35+
content: "{{ config_checksum }}"
36+
dest: /opt/threatstack/etc/.config_checksum
37+
owner: root
38+
group: root
39+
mode: 0644
40+
register: config_file
41+
when: threatstack_agent_config_args != None
42+
43+
- name: Agent setup
44+
command: "{{ setup_string }}"
45+
register: setup_result
46+
changed_when: False
47+
48+
- name: Wait 5 seconds
49+
pause:
50+
seconds: 5
51+
52+
- name: Agent config
53+
command: "{{ config_string }}"
54+
when: config_file.changed
55+
56+
- name: Restart tsagent
57+
service: name=threatstack state=restarted
58+
when: setup_file.changed or config_file.changed
59+
60+
- name: Wait 5 seconds
61+
pause:
62+
seconds: 5
63+
when: setup_file.changed or config_file.changed
64+
65+
- name: Test agent state
66+
command: tsagent status
67+
register: tsagent_status
68+
retries: 5
69+
delay: 2
70+
until: tsagent_status.rc == 0
71+
when: setup_file.changed or config_file.changed
72+
tags:
73+
- checkstate
74+
75+
- name: Ensure agent is running
76+
service: name=threatstack state=started

0 commit comments

Comments
 (0)