Ansible Playbook for Localhost Development Setup: Installing Nginx, Docker, and Node.js
yml
---
- name: Localhost Dev Setup
hosts: localhost
become: true
tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
- name: Install prerequisites
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
- name: Install latest Nginx
ansible.builtin.apt:
name: nginx
state: latest
- name: Add Docker GPG key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker repository
ansible.builtin.apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
state: present
- name: Install latest Docker
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: latest
- name: Add current user to docker group
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: docker
append: yes
- name: Install Node.js (latest LTS)
ansible.builtin.shell: |
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
args:
warn: false
- name: Verify installations
ansible.builtin.shell: |
nginx -v
docker --version
node -v
register: versions
- name: Show installed versions
ansible.builtin.debug:
var: versions.stdout_lines