-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage-tasks.yml
199 lines (175 loc) · 7.04 KB
/
manage-tasks.yml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
- name: Reset variables
set_fact:
tsk_gid: 0
batch_data: []
title_prefix: "({{ customer_name }}) - ({{ opp_number }}) - ({{ csv_index+1 }}/{{ num_ops }})"
# Loop through project_tasks looking for a matching task name that contains the opportunity number
- name: Opp {{ title_prefix }} - check to see if the task already exists
vars:
_query: "[?contains(name, '{{ opp_number }}')].gid | [0]"
set_fact:
tsk_gid: "{{ project_tasks.json.data | to_json | from_json | json_query(_query) }}"
- name: Opp {{ title_prefix }} - print tsk_gid
debug:
msg: "Existing task found: {{ tsk_gid }}"
when: tsk_gid | int > 0
# Match the gid of the asana templates to clone (TMP-RENEWAL, TMP-NETNEW, and TMP-INACTIVE)
- name: Opp {{ title_prefix }} - match the gid for the Asana template to clone
block:
- name: Opp {{ title_prefix }} - set asana_task_template({{ opp_record_type }})
set_fact:
asana_task_template: "{{ asana_template_tasks[opp_record_type] }}"
when: tsk_gid | int == 0
rescue:
- name: Opp {{ title_prefix }} - set asana_task_template to (inactive)
set_fact:
asana_task_template: "{{ asana_template_tasks['inactive'] }}"
- name: Opp {{ title_prefix }} - print asana_task_template
debug:
var: asana_task_template
verbosity: 2
when: tsk_gid | int == 0
# Clone the asana_task_template with all of the subtasks preloaded
- name: Opp {{ title_prefix }} - cloning asana_task_template({{ asana_task_template }})
uri:
url: "{{ asana_api }}/tasks/{{ asana_task_template }}/duplicate"
headers:
Authorization: "{{ asana_token }}"
method: POST
body:
data:
include:
- attachments
- dependencies
- notes
- assignee
- parent
- projects
- subtasks
- notes
- tags
name: "{{ opp_number }} - {{ opp_name }}"
body_format: json
validate_certs: "{{ validate_certs }}"
status_code: 200,201
when: tsk_gid | int == 0
register: cloned_task
# Set tsk_gid to the newly cloned task
- name: Opp {{ title_prefix }} - set tsk_gid of new task
set_fact:
tsk_gid: "{{ cloned_task.json.data.new_task.gid }}"
when: tsk_gid | int == 0
- name: Opp {{ title_prefix }} - print tsk_gid
debug:
var: tsk_gid
verbosity: 2
# Match the gid of the asana Opportunity Type (Renewal, Net New, Other, etc)
# RFE: Look through project_details for the gid to make this more dynamic
- name: Opp {{ title_prefix }} - block for setting the Opportunity type
block:
- name: Opp {{ title_prefix }} - set asana_opp_type({{ opp_record_type }})
set_fact:
asana_opp_type: "{{ asana_opp_types[opp_record_type] }}"
rescue:
- name: Opp {{ title_prefix }} - set asana_opp_type to Other
set_fact:
asana_opp_type: "{{ asana_opp_types['Other'] }}"
- name: Opp {{ title_prefix }} - print asana_opp_type
debug:
var: asana_opp_type
verbosity: 2
# Match the gid of the asana section (Commit, Best Case, Pipeline, Closed)
- name: Opp {{ title_prefix }} - set section_gid to forecast_category({{ forecast_category }})
set_fact:
section_gid: "{{ asana_sections[forecast_category] }}"
when: forecast_category | length > 0
- name: Opp {{ title_prefix }} - print section_gid
debug:
var: section_gid
verbosity: 2
# Match the gid of the asana Fiscal Quarters (Q1, Q2, Q3, Q4)
- name: Opp {{ title_prefix }} - set asana_fq({{ fiscal_quarter }})
set_fact:
asana_fq: "{{ asana_fiscal_quarters[fiscal_quarter] }}"
when: fiscal_quarter | length > 0
- name: Opp {{ title_prefix }} - print asana_fq
debug:
var: asana_fq
verbosity: 2
# Match the gid of the asana ForecastCategory (Commit, Best Case, Pipeline, Closed)
- name: Opp {{ title_prefix }} - set forecast_category({{ forecast_category }})
set_fact:
asana_fc: "{{ forecast_categories[forecast_category] }}"
when: forecast_category | length > 0
- name: Opp {{ title_prefix }} - print asana_fc
debug:
var: asana_fc
verbosity: 2
# Match the gid of the Asana Stage
- name: Opp {{title_prefix}} - set asana_stage({{ stage }})
set_fact:
asana_stage: "{{ sfdc_stages[stage] }}"
when: stage | length > 0
- name: Opp {{ title_prefix }} - print asana_stage
debug:
var: asana_stage
verbosity: 2
- name: Opp {{ title_prefix }} - create dictionary based on updates and custom fields
set_fact:
update_tasks_data:
completed: "{{ (forecast_category=='Closed' or forecast_category=='Omitted') | ternary(true,false) }}"
custom_fields:
# custom text fields
'1182531335993465': "{{ opp_owner }}" # AE (Global)
'1195217282482432': "{{ opp_number }}" # Opportunity Number (Global)
'1200113936496375': "https://redhat.my.salesforce.com/{{ opp_id }}" # SFDC Link (Global)
'1200114261516681': "{{ tb }}" # TB (Global)
'1200038584667544': "{{ syb }}" # SYB (Global)
'1200176345337880': "{{ tech_win_date }}" # Technical Win Date (Global)
'1200204527019766': "{{ reseller }}" # Channel (Global)
'1200204611344740': "{{ distributor }}" # Distributor (Global)
'1200204672011254': "{{ leadsource }}" # LeadSource (Global)
'1200204527686759': "{{ channel }}" # Channel (Global)
# custom dropdown field names
'1200008973756201': "{{ asana_fq | default(omit) }}" # Fiscal Quarter (Global)
'1200046075857084': "{{ asana_opp_type | default(omit) }}" # OpportunityType (Global)
'1200235633617549': "{{ asana_fc | default(omit) }}" # ForecastCategory (Global)
'1200291243594269': "{{ asana_stage | default(omit) }}" # SFDC Stage (Global)
due_on: "{{ close_date }}" # close_date
# reset the task name in case it was changed
name: "{{ opp_number }} - {{ opp_name }}"
notes: |
Opportunity Owner: {{ opp_owner }}
Global Customer Name: {{ customer_name }}
Reason: ({{ reason1 }} {{ reason2 }})
Next Step:
{{ next_step }}
Description:
{{ description | truncate(1024,True) }}
- name: Opp {{ title_prefix }} - add appropriate section data to batch data
set_fact:
batch_data: "{{ batch_data + [{'relative_path':'/sections/' + section_gid + '/addTask', 'method':'POST', 'data': {'task': tsk_gid} } ] }}"
- name: Opp {{ title_prefix }} - add opp updates to batch data
set_fact:
batch_data: "{{ batch_data + [{'relative_path':'/tasks/' + tsk_gid + '', 'method':'PUT', 'data': update_tasks_data } ] }}"
- name: Opp {{ title_prefix }} - add tag updates to batch data
set_fact:
batch_data: "{{ batch_data + [{'relative_path':'/tasks/' + tsk_gid + '/addTag', 'method':'POST', 'data':{'tag': product_tags[pt] }}] }}"
loop: "{{ products.split('|') }}"
when: pt != 'ERROR'
loop_control:
loop_var: pt
- name: Opp {{ title_prefix }} - performing bulk update of opp
uri:
url: "{{ asana_api }}/batch"
headers:
Authorization: "{{ asana_token }}"
method: POST
body:
data:
actions:
"{{ batch_data }}"
body_format: json
validate_certs: "{{ validate_certs }}"
status_code: 200,201
register: batch_results