anchor.diff:    roles:
       - role: elasticsearch
   ----
  -But deploying every host in serial makes deployment endless.
  +But deploying every host in serial takes a very long time and makes deployment endless.
   
   == Refactoring the role
   
  -The main idea is to split the role into multiple steps:
  +The main idea is to split the role into multiple steps, and do as much as possible in parallel:
   
  -1. *In Parrallel*: deploy as much things as possible: system settings, software settings, software binaries.
  +1. *In Parallel*: Deploy system settings, software settings, software binaries.
     But don't stop anything and don't remove anything.
   2. *In Serial*:
     * Stop the node
  
positive.code:   * Start the node
  3. *In Parallel*: finish applying settings on running cluster and remove old files and binaries.
  
  Each step is described in its own YAML file: `before.yml`, `stop_start.yml` and `after.yml`.
  The role entry point routes to the appropriate step using role variable named `elasticsearch_step`:
  
  .roles/elasticsearch/tasks/main.yml
  [source,yaml]
  ----
    - name: "Running step {{ elasticsearch_step }}"
      include: "{{ elasticsearch_step }}.yml"
  ----
  
  == Refactoring the playbook
  
  Now in the playbook we will call the role 3 times, each step being called independently.
  
  .playbook.yml
  [source,yaml]
  
negative.code:     - role: elasticsearch
        elasticsearch_step: "after"
  ----
  
  Or even simpler, we can use `all` step:
  
  .playbook.yml
  [source,yaml]
  ----
  # New cluster
  - hosts: elasticsearch
    any_errors_fatal: true
    roles:
      - role: elasticsearch
        elasticsearch_step: "all"
  ----
  
  == Hot configuration
  
  Most of the time, I am running my Ansible playbook only to change settings that don't need nodes to be restarted.
  The trick is here to detect in the `before` step whether nodes should be restarted or not:
  Version upgrade? Configuration that can not be hot reloaded?
  On lucky days, you can skip the expensive `stop_start` step and have a quick deploy.
  