Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. ---
  2. - name: Find existing AMI if it exists
  3. local_action:
  4. module: command aws ec2 describe-images --owners self --filters Name=tag-value,Values={{deploy_env}}-{{service}} --query Images[0].ImageId --output text --region {{region}}
  5. register: deletable_ami
  6. ignore_errors: True
  7. tags:
  8. - build
  9. - configure
  10.  
  11. - name: Delete AMI snapshot
  12. local_action:
  13. module: ec2_ami
  14. region: "{{region}}"
  15. image_id: "{{deletable_ami.stdout}}"
  16. state: absent
  17. ignore_errors: True
  18. tags:
  19. - build
  20. - configure
  21.  
  22. - name: Create AMI snapshot
  23. local_action:
  24. module: ec2_ami
  25. region: "{{region}}"
  26. instance_id: "{{tid}}"
  27. wait: yes
  28. no_reboot: no
  29. name: "{{ami_name}}"
  30. state: present
  31. register: ami
  32. tags:
  33. - build
  34. - configure
  35.  
  36. - name: Tag the AMI Snapshot
  37. local_action:
  38. module: ec2_tag
  39. resource: "{{ami.image_id}}"
  40. region: "{{region}}"
  41. state: present
  42. tags:
  43. Name: "{{deploy_env}}-{{service}}"
  44. Environment: "{{deploy_env}}"
  45. tags:
  46. - build
  47. - configure
  48.  
  49. - name: Get current date in UTC
  50. local_action:
  51. module: command date -u +%Y-%m-%d_%H_%M_%S_UTC
  52. register: keydate
  53. tags:
  54. - build
  55. - configure
  56.  
  57. - name: Create Launch Configuration for ASG
  58. local_action:
  59. module: ec2_lc
  60. name: "{{deploy_env}}-{{service}}-{{keydate.stdout}}"
  61. image_id: "{{ami.image_id}}"
  62. key_name: "{{key_name}}"
  63. security_groups: ["{{sg.group_id}}"]
  64. instance_type: "{{instance_type}}"
  65. instance_profile_name: "{{instance_profile_name | default(omit)}}"
  66. assign_public_ip: "{{assign_public_ip}}"
  67. user_data: "{{bash_script | default(omit)}}"
  68. state: present
  69. region: "{{region}}"
  70. with_items: ec2.results
  71. register: lc
  72. tags:
  73. - build
  74. - configure
  75.  
  76. - name: Create Auto Scale Group for service
  77. local_action:
  78. module: ec2_asg
  79. name: "{{deploy_env}}-{{service}}"
  80. health_check_period: 300
  81. health_check_type: "{{asg_health_type | default(omit)}}"
  82. launch_config_name: "{{deploy_env}}-{{service}}-{{keydate.stdout}}"
  83. region: "{{region}}"
  84. min_size: 1
  85. max_size: "{{max}}"
  86. load_balancers: "{{elb_name | default(omit)}}"
  87. desired_capacity: "{{ideal}}"
  88. replace_all_instances: yes
  89. replace_batch_size: 1
  90. wait_for_instances: True
  91. vpc_zone_identifier: ["{{all_mgmt_subnets | join(', ')}}"]
  92. tags:
  93. - Name: "{{deploy_env}}-{{service}}-{{visibility}}"
  94. - deploy_env: "{{deploy_env}}"
  95. - service: "{{service}}"
  96. - region: "{{region}}"
  97. - service_region: "{{service}}-{{region}}"
  98. register: asg_result
  99. tags:
  100. - build
  101. - configure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement