Anything you do to Ansible twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.
1. Install it reproducibly
python3 -m pip install --user ansible
ansible --version
ansible all -i inventory.ini -m ping2. Describe the desired state
A playbook that installs and enables nginx idempotently.
- hosts: web
become: true
tasks:
- name: Install nginx
ansible.builtin.package:
name: nginx
state: present
- name: Ensure nginx is running and enabled
ansible.builtin.service:
name: nginx
state: started
enabled: true
- name: Deploy site config
ansible.builtin.template:
src: site.conf.j2
dest: /etc/nginx/conf.d/site.conf
notify: reload nginx
handlers:
- name: reload nginx
ansible.builtin.service: { name: nginx, state: reloaded }3. Run it from CI
Lint playbooks and run in check mode in CI.
- run: ansible-lint
- run: ansible-playbook -i inventory.ini site.yml --check --diffWant senior help putting Ansible to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.