A
A
Alexey Yarkov2017-03-13 18:55:30
linux
Alexey Yarkov, 2017-03-13 18:55:30

How to write a playbook for Ansible correctly?

I'm trying to attach Ansible to the project to simplify the deployment.
To update the code on the VPS, you must perform the following steps:

  1. ./stop.sh
  2. git pull origin master
  3. ./eslint.sh
  4. ./build.sh
  5. ./builddocs.sh
  6. ./updatekey.sh
  7. ./start.sh

Well, of course, if some script fails, for example, eslint did not work, then we interrupt the process and notify me)))
For now, here's what we have:
---
- hosts: production

  tasks:
    - name: Stop app
    shell: ./stop.sh

    - name: Start git pull
      git: [email protected]:repo/projectname.git version=master dest=/home/user/projects/projectname
      sudo: yes
      sudo_user: user
      notify:
        - Start eslint

  handlers:
    - name: Start eslint
      shell: ./eslint.sh
      notify:
        - Start build

    - name: Start build
      shell: ./build.sh
      notify:
        - Start builddocs

    - name: Start builddocs
      shell: ./builddocs.sh
      notify:
        - Start updatekey

    - name: Start updatekey
      shell: ./updatekey.sh
      notify:
        - Start app

    - name: Start app
      shell: ./start.sh

I didn’t launch it, because I’m afraid))) Is
everything correct or should I add something?
And if you give a link to a description of the structure of the playbook file in Russian, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2017-03-14
@opium

what kind of tin you have
, look at the ready-made scripts,
your scripts should be scattered into commands in the ansible itself and not call them
, well, you just need to execute them in turn and not call them in a chain through handlers,
start and stop the task in systemd and use it through service

O
OnYourLips, 2017-03-13
@OnYourLips

The documentation is very clear, it is enough for understanding. But you need to know English.
By the way, your example is old. Here is the old task format, and the use of sudo instead of become.
In addition, instead of shell, you had to use service to start / stop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question