-
Notifications
You must be signed in to change notification settings - Fork 0
/
100.3_playbook_copy_and_deploy_windows_agent_s3.yaml
165 lines (151 loc) · 5.35 KB
/
100.3_playbook_copy_and_deploy_windows_agent_s3.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Example Playbok to deploy agents
- name: Deploy App Agent
hosts: windows
vars:
agent_src: /tmp
s3_bucket: dps-products
s3_host: http://ansible.demo.local:9000
access_key: minioadmin
secret_key: Password123!
s3_container: powerprotect
release: 19.17
package:
vars_files:
- ./vars/main.yml
- ./vars/agents_vars.yaml
- "{{ agent_src }}/agents.yaml"
tasks:
- name: Checking Required Variable ppdm_fqdn
fail:
msg: "We do not have ppdm fqdn set !"
when: (ppdm_fqdn is not defined) or (ppdm_fqdn|length <= 8)
delegate_to: localhost
- name: Create a directory if it does not exist
ansible.builtin.file:
path: "{{ agent_src }}"
state: directory
#mode: '0755'
delegate_to: localhost
- name: Copy Latest Agent Version from S3
amazon.aws.aws_s3:
bucket: "{{ s3_bucket}}"
object: "{{ s3_container }}/{{ release }}/agents/agents.yaml"
dest: "{{ agent_src }}/agents.yaml"
mode: get
encrypt: false
endpoint_url: "{{ s3_host }}"
access_key: "{{ access_key }}"
secret_key: "{{ secret_key }}"
when: not ansible_check_mode
delegate_to: localhost
- name: Include Agent Vars from S3
ansible.builtin.include_vars:
dir: "{{ agent_src }}"
files_matching: agents.yaml
- name: Create a directory if it does not exist
ansible.builtin.file:
path: "{{ agent_src }}/{{ app_agent | dirname }}"
state: directory
mode: '0755'
delegate_to: localhost
- name: Copy Agents from S3
amazon.aws.aws_s3:
bucket: "{{ s3_bucket}}"
object: "{{ s3_container }}/{{ release }}/agents/{{ app_agent }}"
dest: "{{ agent_src }}/{{ app_agent }}"
mode: get
encrypt: false
endpoint_url: "{{ s3_host }}"
access_key: "{{ access_key }}"
secret_key: "{{ secret_key }}"
when: not ansible_check_mode
delegate_to: localhost
- name: Copy agent to {{ ansible_fqdn }}
ansible.windows.win_copy:
src: "{{ agent_src }}/{{ app_agent }}"
dest: C:/Temp/
- name: Unzip Agents
community.windows.win_unzip:
src: "C:/Temp/{{ app_agent | basename }}"
dest: C:/swdist
register: unzip
- name: Find files in path based on regex pattern
ansible.windows.win_find:
paths: c:/swdist/ntx64, c:/swdist/win_x64
patterns: "*-{{ agent_release }}.exe"
register: find_file
- name: "Install with fsagent {{ find_file.files[0].path }} on {{ ansible_fqdn }}"
vars:
preferred_address: |-
{%- if by_ip is defined -%}
{%- if ansible_interfaces[0].ipv4.address is defined -%}
{{ ansible_interfaces[0].ipv4.address }}
{%- else -%}
{{ ansible_interfaces[0].ipv4[0].address }}
{%- endif -%}
{%- else -%}
{{ ansible_fqdn }}
{%- endif -%}
ansible.windows.win_package:
path: "{{ find_file.files[0].path }}"
product_id: "{{ app_agent_product_id }}"
arguments:
- /s
- PPDMHostName={{ ppdm_fqdn | regex_replace('^https://') }}
- EnableFirewallRules=1
- PreferredAddress={{ preferred_address }}
- EnableScriptRequests=1
when: app_agent == fs_agent_windows
- name: "Install with msappagent {{ find_file.files[0].path }} on {{ ansible_fqdn }}"
vars:
preferred_address: |-
{%- if by_ip is defined -%}
{%- if ansible_interfaces[0].ipv4.address is defined -%}
{{ ansible_interfaces[0].ipv4.address }}
{%- else -%}
{{ ansible_interfaces[0].ipv4[0].address }}
{%- endif -%}
{%- else -%}
{{ ansible_fqdn }}
{%- endif -%}
ansible.windows.win_package:
path: "{{ find_file.files[0].path }}"
product_id: "{{ app_agent_product_id | default('') }}"
arguments:
- /s
- PPDMHostname={{ ppdm_fqdn | regex_replace('^https://') }}
- EnableFirewallRules=1
- PreferredAddress={{ preferred_address }}
- EnableSSMS={{ enable_ssms | default(0) }}
- InstallPPDMAgentCheckBox=1
- EnableScriptRequests=1
when: "'databasehosts' in group_names"
- name: "Install with mexchangeagent {{ find_file.files[0].path }} on {{ ansible_fqdn }}"
vars:
preferred_address: |-
{%- if by_ip is defined -%}
{%- if ansible_interfaces[0].ipv4.address is defined -%}
{{ ansible_interfaces[0].ipv4.address }}
{%- else -%}
{{ ansible_interfaces[0].ipv4[0].address }}
{%- endif -%}
{%- else -%}
{{ ansible_fqdn }}
{%- endif -%}
ansible.windows.win_package:
path: "{{ find_file.files[0].path }}"
product_id: "{{ app_agent_product_id | default('') }}"
arguments:
- /s
- PPDMHostname={{ ppdm_fqdn | regex_replace('^https://') }}
- EnableFirewallRules=1
- PreferredAddress={{ preferred_address }}
- EnableItemPoint={{ enable_itempoint | default(0) }}
- InstallPPDMAgentCheckBox=1
- EnableScriptRequests=1
when: "'exchangehosts' in group_names"
- name: Set service startup mode to auto and ensure it is started
ansible.windows.win_service:
name: AgentService
state: started
start_mode: delayed