How to Use Ansible Playbooks to Automate Complex Tasks on Multiple Remote Servers – Part 2

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. vinay says:

    I get this error:
    TASK [replace default index.html file] *****************************************
    fatal: [192.168.0.104]: FAILED! => {“changed”: false, “checksum”: “105317b5614e0de4463045e059a76aab62210ffd”, “failed”: true, “msg”: “Destination /var/www/html not writable”}

    NO MORE HOSTS LEFT *************************************************************
    [WARNING]: Could not create retry file ‘/etc/ansible/playbooks/apache.retry’. [Errno 13] Permission denied:
    ‘/etc/ansible/playbooks/apache.retry’

    please help

  2. vinay says:

    On executing the command – ansible-playbook /etc/ansible/playbooks/apache.yml

    I get below error:

    TASK [replace default index.html file] *****************************************
    fatal: [192.168.0.104]: FAILED! => {“changed”: true, “failed”: true, “msg”: “Destination /var/www/html not writable”}

    NO MORE HOSTS LEFT *************************************************************
    [WARNING]: Could not create retry file ‘/etc/ansible/playbooks/apache.retry’. [Errno 13] Permission denied:
    ‘/etc/ansible/playbooks/apache.retry’

    please suggest

  3. vinay says:

    Hi friends,

    Try adding this below lines & it works.


    – hosts: webservers
    vars:
    http_port: 80
    max_clients: 200
    remote_user: root
    tasks:
    – name: ensure apache is at the latest version
    yum: name=httpd state=latest
    – name: write the apache config file
    template: src=/static_files/index.html dest=/var/www/html mode=0644
    notify:
    – restart apache
    – name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
    handlers:
    – name: restart apache
    service: name=httpd state=restarted

  4. Sadashiv says:

    I too received this error when configured.. so, it clearly an indentation problem. So, i copied the code from http://docs.ansible.com/ansible/playbooks_intro.html and it worked.

    • Gabriel A. Cánepa says:

      @Sadashiv,
      As other users have pointed out, copying and pasting directly from this article into a terminal results in indentation errors.
      @Ravi,
      Please place a notice in this article saying so.

  5. Hi everyone,
    Regarding the “ERROR: Syntax Error while loading YAML” message, it is hard to assess based on the code formatting as viewed in the comment area. Please take a look here (https://github.com/ansible/ansible/issues/8243) and make sure you don’t have indentation errors or typos throughout the configuration files. If this does not resolve your issues, please upload the playbook files to an online storage service (such as Pastebin) and share the details of your system (distribution + version and Ansible version) so that I can reproduce.

  6. Gabriel,

    I have encounter an issue

    ERROR! Syntax Error while loading YAML.

    The error appears to have been in ‘/etc/ansible/playbooks/apache.yml’: line 2, column 8, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


    – hosts: web-servers
    ^ here

    My playbook as follows


    – hosts: web-servers
    vars:
    http_port: 80
    max_clients: 200
    remote_user: root
    tasks:
    – name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
    – name: replace default index.html file
    copy: src=/static_files/index.html dest=/var/www/html/ mode=0644
    notify:
    – restart apache
    – name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
    handlers:
    – name: restart apache
    service: name=httpd state=restarted

  7. anil says:

    I am getting error after loading the ansible-playbook

    ERROR: Syntax Error while loading YAML script, /etc/ansible/playbooks/apache.yml
    Note: The error may actually appear before this position: line 7, column 4

    remote_user: root
    tasks:

  8. Thanks for this useful article, actually I was working on it this night to make something like a monitor for Apache, MySQL, Exim, FTP, Load Average and Disk Usage, which will execute a command and send an email in case of failed, I gone through hard time to be honest but finally made it.

    • What are the difficulties you encountered while setting up and using Ansible? Feel free to share with the rest of the community – that way we will all benefit from each other’s experience.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?