Skip to content

Commit

Permalink
migrate to ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Feb 23, 2024
1 parent d3f89b2 commit fc858d2
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude_paths:
- .github/
skip_list:
- risky-file-permissions
- risky-file-permissions
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.direnv/
.vscode/
8 changes: 7 additions & 1 deletion base.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
---
- name: Base server AMI

# Create a server base AMI

- name: Server base AMI
hosts: 127.0.0.1
connection: local
become: true
roles:
- common
- unattended_upgrades
- useraccounts
- aws_ssm
- aws_codedeploy
- security
4 changes: 4 additions & 0 deletions packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ packer {
version = ">= 1.2.0"
source = "github.com/wata727/amazon-ami-management"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions roles/aws_codedeploy/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---

# Install current AWS Codedeploy agent

- name: Install Codedeploy agent dependencys
ansible.builtin.apt:
name:
- ruby
- gdebi-core

- name: Copy install package
ansible.builtin.get_url:
url: https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
dest: /tmp/codedeploy-installer
owner: root
group: root
mode: '0755'

- name: Install Codedeploy agent
ansible.builtin.command: /tmp/codedeploy-installer auto
changed_when: true

- name: Keep less Codedeploy revisions
ansible.builtin.lineinfile:
path: /etc/codedeploy-agent/conf/codedeployagent.yml
regexp: '^:max_revisions'
line: ':max_revisions: 1'

- name: Enable Codedeploy agent service
ansible.builtin.systemd:
name: codedeploy-agent
enabled: true
masked: false
21 changes: 21 additions & 0 deletions roles/aws_ssm/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

# Install AWS SSM agent

- name: SSM agent install package for arm64 architecture
ansible.builtin.apt:
deb: https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_arm64/amazon-ssm-agent.deb
when:
- ansible_facts['architecture'] == "aarch64"

- name: SSM agent install package for x86_64 architecture
ansible.builtin.apt:
deb: https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
when:
- ansible_facts['architecture'] == "x86_64"

- name: Enable SSM agent service
ansible.builtin.systemd:
name: amazon-ssm-agent
enabled: true
masked: false
5 changes: 3 additions & 2 deletions roles/common/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
group: root
mode: '0644'

- name: Generate locales for en_US and de_DE
ansible.builtin.shell: locale-gen
- name: Generate locales for en_US and de_DE
ansible.builtin.command: locale-gen
changed_when: true

# Install AWS CLI

Expand Down
9 changes: 9 additions & 0 deletions roles/security/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

# Disable standard ubuntu user

- name: Disable Ubuntu default user
ansible.builtin.user:
name: ubuntu
password: "!"
expires: 1
8 changes: 0 additions & 8 deletions roles/useraccounts/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,3 @@
owner: root
group: root
mode: '0440'

# Disable standard ubuntu user

- name: Create user and homedir
ansible.builtin.user:
name: ubuntu
password: "!"
expires: 1

0 comments on commit fc858d2

Please sign in to comment.