-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible.yml
47 lines (42 loc) · 1.75 KB
/
ansible.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
---
- hosts: localhost
vars:
aws_region: eu-west-1
bucket_name: tgbot1-bucket
cf_template_s3_key: cloudformation.json
cf_template_path: cloudformation.json
lambda_s3_key: lambda2.zip
lambda_path: output.zip
cf_stack_name: tgbot1
tg_bot_token: "{{ lookup('env','TELEGRAM_BOT_TOKEN') }}"
tasks:
- name: Create project S3 bucket
s3: bucket={{ bucket_name }} region={{ aws_region }} mode=create
- name: Copy lambda code to S3 bucket
s3: bucket={{ bucket_name }} region={{ aws_region }} mode=put overwrite=different object={{ lambda_s3_key }} src={{ lambda_path }}
- name: Copy cloudformation template to S3 bucket
s3: bucket={{ bucket_name }} region={{ aws_region }} mode=put overwrite=different object={{ cf_template_s3_key }} src={{ cf_template_path }}
- name: Create cloudformation stack
cloudformation:
stack_name: "{{ cf_stack_name }}"
state: present
region: "{{ aws_region }}"
disable_rollback: true
template: "{{ cf_template_path }}"
template_parameters:
LambdaS3Bucket: "{{ bucket_name }}"
LambdaS3Key: "{{ lambda_s3_key }}"
ApiName: "ansible-tgbot1"
TelegramBotToken: "{{ tg_bot_token }}"
tags:
Stack: "{{ cf_stack_name }}"
register: stack
- name: update lambda function
shell: aws lambda update-function-code --region {{ aws_region }} --function-name {{ stack.stack_outputs.LambdaArn }} --s3-bucket {{ bucket_name }} --s3-key {{ lambda_s3_key }}
- name: update telegram webhook
uri:
url: https://api.telegram.org/{{ tg_bot_token }}/setWebhook
method: POST
body_format: json
body:
url: "{{ stack.stack_outputs.LambdaEndpoint }}"