Write a playbook that uses tags so you can run only the config part.
BeginnerHands-onWrite-an-Ansible-playbook tasks
Answer
- hosts: web
become: true
tasks:
- name: Install nginx
ansible.builtin.apt: { name: nginx, state: present }
tags: [install]
- name: Deploy config
ansible.builtin.template: { src: nginx.conf.j2, dest: /etc/nginx/nginx.conf }
tags: [config]
notify: Reload nginx
handlers:
- name: Reload nginx
ansible.builtin.service: { name: nginx, state: reloaded }
ansible-playbook site.yml --tags config
ansible-playbook site.yml --list-tags
Key trick → Tags let you rerun one slice of a big playbook in seconds. Handlers notified by tagged tasks still run.
More on Write-an-Ansible-playbook tasks
Write a playbook that installs and starts Nginx on Ubuntu web servers.BeginnerWrite an inventory with groups, a group of groups, and per-group variables.BeginnerWrite a playbook that deploys a config file from a Jinja2 template and restarts the service only if it changed.BeginnerWrite a role structure for a Node.js app and show what goes in each folder.IntermediateWrite a task that creates multiple users with SSH keys from a list.BeginnerWrite a rolling deploy playbook: 2 servers at a time, removed from the load balancer during the update.Advanced