Skip to content

Instantly share code, notes, and snippets.

@coilysiren
Last active May 14, 2021 18:56
Show Gist options
  • Save coilysiren/3d4903b06c251b485f0a63d060b2a6d8 to your computer and use it in GitHub Desktop.
Save coilysiren/3d4903b06c251b485f0a63d060b2a6d8 to your computer and use it in GitHub Desktop.
# via the following link, slightly modified
# https://github.com/nginxinc/ansible-role-nginx/blob/ead9de5ce6d29b299d8b139a82178926bb0f2c4b/tasks/opensource/install-source.yml
- name: (Centos/RHEL) Install build tools
yum:
name:
- "@Development tools"
- ca-certificates
- gcc
- gd
- gd-devel
- glibc
- glibc-common
- perl-core
- wget
- zlib-devel
update_cache: yes
when: ansible_facts['os_family'] == "RedHat"
- name: (Debian/Ubuntu) Install build tools
apt:
name:
- build-essential
- checkinstall
- libtemplate-perl
- python3-minimal
- perl
- tar
- zlib1g-dev
update_cache: yes
when: ansible_facts['os_family'] == "Debian"
- name: (Alpine Linux) Install build tools
apk:
name:
- alpine-sdk
- build-base
- git
- openrc
- perl
- python3
- linux-headers
- tar
- wget
update_cache: yes
when: ansible_facts['os_family'] == "Alpine"
# via the following link, slightly modified
# https://github.com/ansible-collections/community.mongodb/blob/40f7190b664615dfeb0afd78589d40d8f78ba1c0/roles/mongodb_mongod/tasks/main.yml
- name: Check if we are in docker
stat:
path: is_docker.txt
register: is_docker
- name: Ensure mongod package is installed
package:
name: "{{ mongod_package }}"
register: _pkg
until: _pkg is succeeded
retries: 5
- name: Ensure db_path dir exists
file:
path: "{{ db_path }}"
state: directory
owner: "{{ mongodb_user }}"
group: "{{ mongodb_group }}"
- name: Copy config file
template:
src: "{{ mongod_config_template }}"
dest: /etc/mongod.conf
owner: "{{ mongodb_user }}"
group: "{{ mongodb_group }}"
notify:
- Restart mongod service
- name: Copy keyfile to host
copy:
content: |
{{ openssl_keyfile_content }}
dest: /etc/keyfile
owner: "{{ mongodb_user }}"
group: "{{ mongodb_group }}"
mode: 0400
when: authorization == "enabled"
notify:
- Restart mongod service
- name: Start mongod service
service:
name: "{{ mongod_service }}"
state: started
enabled: yes
when: not (ansible_facts.os_family == 'RedHat'
and ansible_facts.distribution_major_version|int == 8
and is_docker.stat.exists)
# via https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudformation.html
Mappings:
RegionMap:
us-east-1:
AMI: ami-0ff8a91507f77f867
us-west-1:
AMI: ami-0bdb828fd58c52235
eu-west-1:
AMI: ami-047bb4163c506cd98
ap-northeast-1:
AMI: ami-06cd52961ce9f0d85
ap-southeast-1:
AMI: ami-08569b978cc4dfa10
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
UserData:
Fn::Base64: !Ref myWaitHandle
ImageId:
Fn::FindInMap:
- RegionMap
- Ref: AWS::Region
- AMI
myWaitHandle:
Type: AWS::CloudFormation::WaitConditionHandle
Properties: {}
myWaitCondition:
Type: AWS::CloudFormation::WaitCondition
DependsOn: Ec2Instance
Properties:
Handle: !Ref myWaitHandle
Timeout: '4500'
Outputs:
ApplicationData:
Value: !GetAtt myWaitCondition.Data
Description: The data passed back as part of signalling the WaitCondition.
# via https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-rds.html
DBInstance:
Type: AWS::RDS::DBInstance
Properties:
DBName:
Ref: DBName
Engine: MySQL
MasterUsername:
Ref: DBUsername
DBInstanceClass:
Ref: DBClass
DBSecurityGroups:
- Ref: DBSecurityGroup
AllocatedStorage:
Ref: DBAllocatedStorage
MasterUserPassword:
Ref: DBPassword
DBSecurityGroup:
Type: AWS::RDS::DBSecurityGroup
Properties:
DBSecurityGroupIngress:
EC2SecurityGroupName:
Ref: WebServerSecurityGroup
GroupDescription: Frontend Access
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access via port 80 and SSH access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment