-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage-accounts.yml
117 lines (104 loc) · 3.73 KB
/
manage-accounts.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
- name: Reset variables
set_fact:
tsk_gid: 0
batch_data: []
title_prefix: "({{ customer_name }}) - ({{ csv_index+1 }}/{{ num_ops }})"
# Loop through project_tasks looking for a matching task name that matches the global customer name
- name: Opp {{ title_prefix }} - check to see if the task ({{ customer_name }}) already exists
vars:
_query: "[? name==`{{ customer_name }}`].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-ACCOUNT)
- name: Opp {{ title_prefix }} - match the gid for the Asana template to clone
block:
- name: Opp {{ title_prefix }} - set asana_task_template(Account)
set_fact:
asana_task_template: "{{ asana_template_tasks['Account'] }}"
when: tsk_gid | int == 0
rescue:
- name: Opp {{ title_prefix }} - set asana_task_template to (Account)
set_fact:
asana_task_template: "{{ asana_template_tasks['Account'] }}"
- 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: "{{ customer_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 section (Commit, Best Case, Pipeline, Closed)
- name: Opp {{ title_prefix }} - set section_gid to Accounts
set_fact:
section_gid: "{{ asana_sections['Accounts'] }}"
- name: Opp {{ title_prefix }} - print section_gid
debug:
var: section_gid
verbosity: 2
- name: Opp {{ title_prefix }} - create dictionary based on updates and custom fields
set_fact:
update_tasks_data:
custom_fields:
# custom text fields
'1182531335993465': "{{ opp_owner }}" # AE (Global)
'1200113936496375': "https://redhat.my.salesforce.com/{{ account_id }}" # SFDC Link (Global)
# reset the task name in case it was changed
# name: "{{ customer_name }}"
notes: |
Opportunity Owner: {{ opp_owner }}
- 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 }} - 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