Skip to content

Commit eb94c93

Browse files
committed
ansible tasks to install softwares and configure them
1 parent 8d8b802 commit eb94c93

10 files changed

Lines changed: 278 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Versions
2+
terraform_version: "1.5.7"
3+
kubectl_version: "v1.28.0"
4+
ansible_version: "8.6.1"
5+
6+
# Users
7+
dev_user: "ubuntu"
8+
docker_group: "docker"
9+
10+
# System configuration
11+
timezone: "UTC"

ansible/inventory.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[new_vms]
2+
dev-vm ansible_host=192.168.1.150 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa
3+
4+
[new_vms:vars]
5+
ansible_python_interpreter=/usr/bin/python3

ansible/playbook.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- name: Bootstrap fresh VM with complete DevOps toolset
2+
hosts: all
3+
become: yes
4+
gather_facts: yes
5+
6+
vars_files:
7+
- group_vars/all-variables.yaml
8+
9+
tasks:
10+
- name: Include system setup tasks
11+
include_tasks: tasks/system_setup.yml
12+
13+
- name: Include basic tools tasks
14+
include_tasks: tasks/basic_tools.yml
15+
16+
- name: Include Docker tasks
17+
include_tasks: tasks/docker.yml
18+
19+
- name: Include Kubernetes tools tasks
20+
include_tasks: tasks/kubernetes.yml
21+
22+
- name: Include Terraform tasks
23+
include_tasks: tasks/terraform.yml
24+
25+
- name: Include Ansible tasks
26+
include_tasks: tasks/ansible.yml
27+
28+
- name: Include cleanup tasks
29+
include_tasks: tasks/cleanup.yml

ansible/tasks/ansible.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
- name: Install Ansible via pip
3+
pip:
4+
name:
5+
- ansible=={{ ansible_version }}
6+
- ansible-lint
7+
- yamllint
8+
executable: pip3
9+
10+
- name: Install Ansible community general collection
11+
ansible.builtin.command:
12+
cmd: ansible-galaxy collection install community.general
13+
14+
- name: Create ansible directory structure
15+
file:
16+
path: "{{ item }}"
17+
state: directory
18+
mode: '0755'
19+
loop:
20+
- "/home/{{ dev_user }}/ansible"
21+
- "/home/{{ dev_user }}/ansible/inventories"
22+
- "/home/{{ dev_user }}/ansible/roles"
23+
- "/home/{{ dev_user }}/ansible/playbooks"
24+
25+
- name: Create ansible.cfg template
26+
template:
27+
src: ../templates/ansible.cfg.j2
28+
dest: "/home/{{ dev_user }}/ansible/ansible.cfg"
29+
owner: "{{ dev_user }}"
30+
group: "{{ dev_user }}"
31+
mode: '0644'

ansible/tasks/basic_tools.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- name: Install development tools
2+
apt:
3+
name:
4+
- git
5+
- make
6+
- unzip
7+
- jq
8+
- tree
9+
- htop
10+
- ncdu
11+
- python3
12+
- python3-pip
13+
- python3-venv
14+
- postgresql-client
15+
- mysql-client
16+
state: present
17+
18+
- name: Install additional Python tools
19+
pip:
20+
name:
21+
- awscli
22+
- boto3
23+
executable: pip3

ansible/tasks/cleanup.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: Clean up temporary files
3+
file:
4+
path: "{{ item }}"
5+
state: absent
6+
loop:
7+
- /tmp/terraform.zip
8+
- /tmp/helm.tar.gz
9+
- /tmp/tfswitch.tar.gz
10+
- /tmp/terraform-docs.tar.gz
11+
12+
- name: Display completion message
13+
debug:
14+
msg: |
15+
===============================================
16+
BOOTSTRAP COMPLETED SUCCESSFULLY!
17+
===============================================
18+
19+
Installed Tools:
20+
- Docker & Docker Compose
21+
- Kubernetes: kubectl, minikube, kind, Helm
22+
- Terraform {{ terraform_version }} + tfswitch
23+
- Ansible {{ ansible_version }}
24+
- Development tools (git, python, etc.)
25+
26+
Next Steps:
27+
1. Log out and log back in for group changes to take effect
28+
2. Start minikube: minikube start --driver=docker --nodes 3
29+
3. Verify installations:
30+
- docker --version
31+
- kubectl version --client
32+
- terraform version
33+
- ansible --version
34+
35+
Minikube node labeling:
36+
kubectl label node minikube type=application
37+
kubectl label node minikube-m02 type=database
38+
kubectl label node minikube-m03 type=dependent_services
39+
===============================================

ansible/tasks/docker.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: Add Docker GPG key
3+
apt_key:
4+
url: https://download.docker.com/linux/ubuntu/gpg
5+
state: present
6+
7+
- name: Add Docker repository
8+
apt_repository:
9+
repo: "deb [arch={{ ansible_architecture }}] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
10+
state: present
11+
filename: docker
12+
13+
- name: Install Docker packages
14+
apt:
15+
name:
16+
- docker-ce
17+
- docker-ce-cli
18+
- containerd.io
19+
- docker-buildx-plugin
20+
- docker-compose-plugin
21+
state: present
22+
update_cache: yes
23+
24+
- name: Enable and start Docker service
25+
systemd:
26+
name: docker
27+
enabled: yes
28+
state: started
29+
30+
- name: Add user to docker group
31+
user:
32+
name: "{{ dev_user }}"
33+
groups: "{{ docker_group }}"
34+
append: yes

ansible/tasks/kubernetes.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
- name: Download kubectl
3+
get_url:
4+
url: "https://dl.k8s.io/release/{{ kubectl_version }}/bin/linux/amd64/kubectl"
5+
dest: /usr/local/bin/kubectl
6+
mode: '0755'
7+
8+
- name: Download and install minikube
9+
get_url:
10+
url: https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
11+
dest: /usr/local/bin/minikube
12+
mode: '0755'
13+
14+
- name: Install kind (Kubernetes in Docker)
15+
get_url:
16+
url: https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
17+
dest: /usr/local/bin/kind
18+
mode: '0755'
19+
20+
- name: Install Helm
21+
get_url:
22+
url: https://get.helm.sh/helm-v3.12.0-linux-amd64.tar.gz
23+
dest: /tmp/helm.tar.gz
24+
25+
- name: Extract Helm
26+
unarchive:
27+
src: /tmp/helm.tar.gz
28+
dest: /usr/local/bin
29+
remote_src: yes
30+
extra_opts:
31+
- --strip-components=1
32+
creates: /usr/local/bin/helm

ansible/tasks/system_setup.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- name: Update and upgrade system packages
2+
apt:
3+
update_cache: yes
4+
upgrade: dist
5+
cache_valid_time: 3600
6+
7+
- name: Install prerequisites
8+
apt:
9+
name:
10+
- software-properties-common
11+
- apt-transport-https
12+
- ca-certificates
13+
- gnupg
14+
- lsb-release
15+
- curl
16+
- wget
17+
state: present
18+
19+
- name: Set timezone
20+
timezone:
21+
name: "{{ timezone }}"

ansible/tasks/terraform.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
- name: Create terraform directory
3+
file:
4+
path: /opt/terraform
5+
state: directory
6+
mode: '0755'
7+
8+
- name: Download Terraform
9+
get_url:
10+
url: "https://releases.hashicorp.com/terraform/{{ terraform_version }}/terraform_{{ terraform_version }}_linux_amd64.zip"
11+
dest: /tmp/terraform.zip
12+
13+
- name: Extract Terraform
14+
unarchive:
15+
src: /tmp/terraform.zip
16+
dest: /usr/local/bin
17+
remote_src: yes
18+
mode: '0755'
19+
creates: /usr/local/bin/terraform
20+
21+
- name: Install tfswitch (Terraform version manager)
22+
get_url:
23+
url: https://github.com/warrensbox/terraform-switcher/releases/download/0.13.1308/terraform-switcher_0.13.1308_linux_amd64.tar.gz
24+
dest: /tmp/tfswitch.tar.gz
25+
26+
- name: Extract tfswitch
27+
unarchive:
28+
src: /tmp/tfswitch.tar.gz
29+
dest: /usr/local/bin
30+
remote_src: yes
31+
extra_opts:
32+
- --strip-components=1
33+
creates: /usr/local/bin/tfswitch
34+
35+
- name: Create tfswitch config directory
36+
file:
37+
path: "{{ ansible_env.HOME }}/.terraform.versions"
38+
state: directory
39+
mode: '0755'
40+
41+
- name: Install terraform-docs
42+
get_url:
43+
url: https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-linux-amd64.tar.gz
44+
dest: /tmp/terraform-docs.tar.gz
45+
46+
- name: Extract terraform-docs
47+
unarchive:
48+
src: /tmp/terraform-docs.tar.gz
49+
dest: /usr/local/bin
50+
remote_src: yes
51+
extra_opts:
52+
- --strip-components=1
53+
creates: /usr/local/bin/terraform-docs

0 commit comments

Comments
 (0)