From Code Self Study Wiki
Jump to: navigation, search

Notes about Ansible:

See also DigitalOcean.


Handlers call a task after another task has completed. In the following example, the "Start Nginx" handler runs after the "Install Nginx" task runs.

- hosts: all

    - name: Install Nginx
      apt: pkg=nginx state=installed update_cache=true
        - Start Nginx

    - name: Start Nginx
      service: name=nginx state=started

From the docs:

"Handlers are just like regular tasks in an Ansible playbook (see Tasks), but are only run if the Task contains a notify directive and also indicates that it changed something. For example, if a config file is changed then the task referencing the config file templating operation may notify a service restart handler. This means services can be bounced only if they need to be restarted. Handlers can be used for things other than service restarts, but service restarts are the most common usage."


File Module

The File module manages files. Example:

- hosts: all
    - website_dir: /var/www/

    - name: Create website directory
      file: dest={{ website_dir }} mode=775 owner=www-data group=www-data