-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Copyright (C) 2017-present Alibaba Cloud, Inc. | ||
|
||
This work is licensed under the Creative Commons Attribution 3.0 Unported License. | ||
To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/deed.en_US. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Add or Remove tags for resources | ||
|
||
- Requires Ansible 2.9 or newer | ||
- Requires Ansible-Alicloud 1.17.0 or newer | ||
- Requires footmark 1.18.0 or newer | ||
|
||
|
||
These playbooks Create ECS and Deploy product on them. | ||
|
||
These playbooks' hosts default to `localhost`. To use, make the file and edit the `hosts` inventory file to include the names or IPs of the servers | ||
you want to deploy. | ||
|
||
Then run the playbook, like this: | ||
|
||
ansible-playbook -i hosts deploy.yml | ||
|
||
When the run is complete, you can login in the Alicloud console to check them. | ||
|
||
|
||
### Ideas for Improvement | ||
We would love to see contributions and improvements, so please fork this | ||
repository on GitHub and send us your changes via pull requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: Create ECS | ||
hosts: localhost | ||
remote_user: root | ||
|
||
roles: | ||
- vpc | ||
- vswitch | ||
- security_group | ||
- instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
- name: Delete resource | ||
hosts: localhost | ||
remote_user: root | ||
|
||
tasks: | ||
- name: Filter instance using name_regex | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name }}' | ||
register: instances | ||
|
||
- name: Changed. Deleting instances | ||
ali_instance: | ||
instance_ids: '{{instances.ids}}' | ||
force: True | ||
state: absent | ||
|
||
|
||
- name: Filter instance using name_regex | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name_a }}' | ||
register: instances | ||
|
||
- name: Changed. Deleting instances with another vswitch | ||
ali_instance: | ||
instance_ids: '{{instances.ids}}' | ||
force: True | ||
state: absent | ||
|
||
|
||
- name: Filter security group using name_regex | ||
ali_security_group_info: | ||
name_prefix: '{{ security_group_name }}' | ||
register: sgs | ||
|
||
- name: Changed. Deleting the security groups | ||
ali_security_group: | ||
name: '{{ item.group_name }}' | ||
vpc_id: '{{item.vpc_id}}' | ||
state: absent | ||
with_items: '{{sgs.groups}}' | ||
|
||
|
||
- name: Get the existing vswitch | ||
ali_vswitch_info: | ||
name_prefix: '{{ vswitch_name }}' | ||
register: vswitches | ||
|
||
- name: Changed. Deleting vswitches | ||
ali_vswitch: | ||
vpc_id: '{{ item.vpc_id}}' | ||
cidr_block: '{{ item.cidr_block}}' | ||
state: absent | ||
with_items: '{{vswitches.vswitches}}' | ||
|
||
- name: Get another vswitch | ||
ali_vswitch_info: | ||
name_prefix: '{{ vswitch_name_a }}' | ||
register: vswitches | ||
|
||
- name: Changed. Deleting vswitches | ||
ali_vswitch: | ||
vpc_id: '{{ item.vpc_id}}' | ||
cidr_block: '{{ item.cidr_block}}' | ||
state: absent | ||
with_items: '{{vswitches.vswitches}}' | ||
|
||
- name: Filter vpc using name_regex | ||
ali_vpc_info: | ||
name_prefix: '{{ vpc_name }}' | ||
register: vpcs | ||
|
||
- name: Changed. Deleting vpcs | ||
ali_vpc: | ||
cidr_block: '{{ item.cidr_block }}' | ||
name: '{{ item.vpc_name }}' | ||
state: absent | ||
with_items: '{{vpcs.vpcs}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
- name: Deploy petstore on ECS | ||
hosts: alicloud | ||
remote_user: root | ||
|
||
tasks: | ||
- name: create property file | ||
shell: "{{item}}" | ||
with_items: | ||
- echo "petstore.loggingLevel = warn" >> /root/antx.properties | ||
- echo "petstore.loggingRoot = /root/pet/logs" >> /root/antx.properties | ||
- echo "petstore.upload = /root/pet/upload" >> /root/antx.properties | ||
- echo "petstore.work = /root/pet" >> /root/antx.properties | ||
|
||
- name: remove java11 | ||
apt: | ||
pkg: | ||
- openjdk-11-jre-headless | ||
- openjdk-11-jdk | ||
state: absent | ||
force_apt_get: True | ||
|
||
- name: build enviroment | ||
apt: | ||
pkg: | ||
- apache2 | ||
- openjdk-8-jre-headless | ||
- openjdk-8-jdk | ||
- git | ||
- maven | ||
force_apt_get: True | ||
|
||
- name: clone project | ||
command: "{{item}}" | ||
with_items: | ||
- git clone https://github.com/webx/citrus-sample.git | ||
|
||
- name: mvn install | ||
command: "{{item}}" | ||
args: | ||
chdir: /root/citrus-sample/petstore | ||
with_items: | ||
- mvn clean install | ||
ignore_errors: True | ||
async: 60 | ||
poll: 10 | ||
|
||
- name: run project | ||
shell: | ||
cmd: nohup mvn jetty:run-war & | ||
chdir: /root/citrus-sample/petstore/web | ||
register: petstore | ||
|
||
- wait_for: port=8081 state=started | ||
|
||
- debug: | ||
msg: http://{{hostvars[inventory_hostname]['public_ip_address']}}:8081?home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
# ecs instance filter parameters | ||
instance_name: 'Instance_From_Ansible_Petstore' | ||
instance_name_a: 'a-Instance_From_Ansible_Petstore' | ||
instance_tags: {For: PetStore, Created: Ansible, From: example/deply} | ||
image_id: "ubuntu_18_04_64_20G_alibase_20190624.vhd" | ||
instance_type: ecs.g5.large | ||
instance_description: "Create a new ECS instance resource via Ansible example deploy-ecs." | ||
host_name: "my-instance-from-ansible" | ||
password: Test12345 | ||
|
||
allocate_public_ip: True | ||
internet_charge_type: "PayByTraffic" | ||
max_bandwidth_in: 200 | ||
max_bandwidth_out: 50 | ||
|
||
system_disk_category: "cloud_ssd" | ||
system_disk_size: 50 | ||
number_of_instances: 2 | ||
|
||
# security group filter parameters | ||
security_group_name: 'Security_Group_From_Ansible' | ||
security_group_tags: {For: PetStore, Created: Ansible, From: example/deply} | ||
|
||
group_description: "Create a new security group resource via Ansible example deploy-ecs." | ||
group_inboundRules: | ||
- ip_protocol: tcp | ||
port_range: 22/22 | ||
source_cidr_ip: 0.0.0.0/0 | ||
priority: 1 | ||
|
||
- ip_protocol: tcp | ||
port_range: 80/80 | ||
source_cidr_ip: 0.0.0.0/0 | ||
priority: 1 | ||
|
||
- ip_protocol: tcp | ||
port_range: 8081/8081 | ||
source_cidr_ip: 0.0.0.0/0 | ||
priority: 1 | ||
|
||
group_outboundRules: | ||
- ip_protocol: tcp | ||
port_range: 80/80 | ||
dest_cidr_ip: 192.168.0.54/32 | ||
priority: 1 | ||
|
||
# vpc filter parameters | ||
vpc_name: 'Vpc_From_Ansible' | ||
vpc_tags: {For: PetStore, Created: Ansible, From: example/deply} | ||
vpc_cidr: "172.16.0.0/12" | ||
vpc_description: "Create a new VPC resource via Ansible example alicloud-ecs-vpc." | ||
|
||
# vswitch parameters | ||
vswitch_cidr: "172.16.1.0/24" | ||
vswitch_cidr_a: "172.22.0.0/16" | ||
vswitch_description: "Create a new VSwitch resource via Ansible example-deploy-ecs." | ||
vswitch_name: 'Vswitch_From_Ansible' | ||
vswitch_name_a: 'a-Vswitch_From_Ansible' | ||
availability_zone: cn-beijing-h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
- name: Get the existing ECS instances | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name }}' | ||
filters: | ||
vpc_id: '{{ vpcs.vpcs.0.id }}' | ||
register: instances | ||
|
||
- name: Get the existing ECS instances | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name_a }}' | ||
filters: | ||
vpc_id: '{{ vpcs.vpcs.0.id }}' | ||
register: instances_a | ||
|
||
- name: Creating two ECS instances | ||
ali_instance: | ||
image: '{{ image_id }}' | ||
type: '{{ instance_type }}' | ||
instance_name: '{{ instance_name }}' | ||
description: '{{ instance_description }}' | ||
host_name: '{{ host_name }}' | ||
password: '{{ password }}' | ||
|
||
allocate_public_ip: '{{ allocate_public_ip }}' | ||
internet_charge_type: '{{ internet_charge_type }}' | ||
max_bandwidth_in: '{{ max_bandwidth_in }}' | ||
max_bandwidth_out: '{{ max_bandwidth_out }}' | ||
|
||
security_groups: ['{{ sgs.groups.0.id }}'] | ||
vswitch_id: '{{ vswitches.vswitches.0.id }}' | ||
|
||
system_disk_category: '{{ system_disk_category }}' | ||
system_disk_size: '{{ system_disk_size }}' | ||
count: '{{ number_of_instances }}' | ||
tags: '{{ instance_tags }}' | ||
when: not instances.instances | ||
|
||
- name: Creating two ECS instances with another vswitch. | ||
ali_instance: | ||
image: '{{ image_id }}' | ||
type: '{{ instance_type }}' | ||
instance_name: '{{ instance_name_a }}' | ||
description: '{{ instance_description }}' | ||
host_name: '{{ host_name }}' | ||
password: '{{ password }}' | ||
|
||
allocate_public_ip: '{{ allocate_public_ip }}' | ||
internet_charge_type: '{{ internet_charge_type }}' | ||
max_bandwidth_in: '{{ max_bandwidth_in }}' | ||
max_bandwidth_out: '{{ max_bandwidth_out }}' | ||
|
||
security_groups: ['{{ sgs.groups.0.id }}'] | ||
vswitch_id: '{{ vswitches_a.vswitches.0.id }}' | ||
|
||
system_disk_category: '{{ system_disk_category }}' | ||
system_disk_size: '{{ system_disk_size }}' | ||
count: '{{ number_of_instances }}' | ||
when: not instances_a.instances | ||
|
||
- name: Get the existing ECS instances | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name }}' | ||
register: instances | ||
|
||
- name: Get the existing ECS instances | ||
ali_instance_info: | ||
name_prefix: '{{ instance_name_a }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- name: Create a VPC security group | ||
ali_security_group: | ||
name: '{{ security_group_name }}' | ||
description: '{{ group_description }}' | ||
vpc_id: '{{vpc.vpc.id}}' | ||
rules: '{{ group_inboundRules }}' | ||
rules_egress: '{{ group_outboundRules }}' | ||
register: group | ||
|
||
- name: Get the existing groups | ||
ali_security_group_info: | ||
name_prefix: '{{ security_group_name }}' | ||
register: sgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Create a new alicloud VPC resource | ||
ali_vpc: | ||
cidr_block: '{{ vpc_cidr }}' | ||
vpc_name: '{{ vpc_name }}' | ||
description: '{{ vpc_description }}' | ||
register: vpc | ||
|
||
- name: Get the existing vpc | ||
ali_vpc_info: | ||
name_prefix: '{{vpc_name}}' | ||
register: vpcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: Create a new alicloud VSwitch resource | ||
ali_vswitch: | ||
alicloud_zone: '{{ availability_zone }}' | ||
cidr_block: '{{ vswitch_cidr }}' | ||
vswitch_name: '{{ vswitch_name }}' | ||
description: '{{ vswitch_description }}' | ||
vpc_id: '{{vpc.vpc.id}}' | ||
register: vswitch | ||
|
||
- name: Create another alicloud VSwitch resource | ||
ali_vswitch: | ||
alicloud_zone: '{{ availability_zone }}' | ||
cidr_block: '{{ vswitch_cidr_a }}' | ||
vswitch_name: '{{ vswitch_name_a }}' | ||
description: '{{ vswitch_description }}' | ||
vpc_id: '{{vpc.vpc.id}}' | ||
register: vswitch_a | ||
|
||
- name: Get the existing vswitch | ||
ali_vswitch_info: | ||
name_prefix: '{{ vswitch_name }}' | ||
filters: | ||
vpc_id: '{{vpc.vpc.id}}' | ||
register: vswitches | ||
|
||
- name: Get the existing vswitch | ||
ali_vswitch_info: | ||
name_prefix: '{{ vswitch_name_a }}' | ||
filters: | ||
vpc_id: '{{vpc.vpc.id}}' | ||
register: vswitches_a |