Exemplo de playbook Ansible

From Basef
Revision as of 19:07, 25 April 2015 by Admin (Talk | contribs)

Jump to: navigation, search

Segue abaixo exemplo de playbook Ansible:

- hosts: all
    http_port: 80
    max_clients: 200
  sudo: yes


  - name: "(VisualEditor) Authentication for parsoid installation"
    sudo: yes
    command: "{{ item }}"
    - gpg --keyserver keys.gnupg.net --recv-keys 5C927F7C
    - gpg -a --export 5C927F7C | apt-key add -

  - name: "(VisualEditor) Add parsoid source url to sources.list"
    apt_repository: repo='deb [arch=amd64] http://parsoid.wmflabs.org:8080/deb wmf-production main' state=present

  - name: "apt-get update"
    sudo: yes
    apt: update_cache=yes
#  - name: "apt-get upgrade"
#    apt: upgrade=dist

  - name: "(VisualEditor) Ensure NodeJS is installed with the latest version"
    apt: name=nodejs state=latest

  - name: "(VisualEditor) Ensure Parsoid is installed with the latest version"
    apt: name=parsoid state=latest force=yes

  - name: "(VisualEditor) Write the Parsoid settings file"
    sudo: yes
    template: src=configuration/parsoid_settings.js dest=/etc/mediawiki/parsoid/settings.js

  - name: "(VisualEditor) Restarting Parsoid"
    sudo: yes
    service: name=parsoid state=restarted

  - name: "Ensure Apache is installed with the lastest version"
    apt: name=apache2 state=latest

  - name: "Enabling Apache Mod Rewrite"
    sudo: yes
    action: command a2enmod rewrite

  - name: "Ensure MySQL is installed with the latest version"
    apt: name=mysql-server state=latest

  - name: "Installing PHP and dependencies"
    action: apt pkg={{item}} state=installed
    - php5
    - php5-cli
    - php5-common
    - php5-curl
    - php5-dev
    - php5-gd
    - php5-geoip
    - php5-imagick
    - php5-intl
    - php5-json
    - php5-mcrypt
    - php5-memcache
    - php5-memcached
    - php5-mysql
    - php5-oauth
    - php5-sqlite
    - php5-xcache
    - php5-xdebug
    - php5-xsl
    - php5-xmlrpc

  - name: "Ensure GIT is installed with the latest version"
    apt: name=git state=latest

  - name: "Write the Apache Virtual Host"
    sudo: yes
    template: src=configuration/apache-virtual-host-model.conf dest=/etc/apache2/sites-available/website.conf

  - name: "Enabling the Apache Virtual Host"
    sudo: yes
    action: command a2ensite website.conf

  - name: "Disabling default Virtual Host"
    sudo: yes
    action: command a2dissite 000-default.conf

  - name: "Replacing the Apache User"
    sudo: yes
    replace: dest=/etc/apache2/envvars regexp='APACHE_RUN_USER=www-data' replace='APACHE_RUN_USER=vagrant'

  - name: "Replacing the Apache Group"
    sudo: yes
    replace: dest=/etc/apache2/envvars regexp='APACHE_RUN_GROUP=www-data' replace='APACHE_RUN_GROUP=vagrant'

  - name: install required packages
    apt: pkg={{ item }} state=latest force=yes update_cache=yes
      - php5-dev
      - php5-mysql
      - gcc
      - libpcre3-dev
      - make

  - name: "Restarting Apache"
    sudo: yes
    service: name=apache2 state=restarted

  - name: "Creating database"
    sudo: yes
    shell: mysql --defaults-file=/etc/mysql/debian.cnf --execute="CREATE DATABASE website"
    register: create_database_task   
    ignore_errors: True

  - name: "Copying database dump to inside the Virtual Machine"
    sudo: yes
    copy: src=database/database_dump.sql dest=/tmp/database_dump.sql
    when: create_database_task|success

  - name: "Importing MySQL Database"
    shell: mysql --defaults-file=/etc/mysql/debian.cnf website < /tmp/database_dump.sql
    when: create_database_task|success

  - name: "Changing database credentials to user, pass and db 'website'"
    shell: mysql --defaults-file=/etc/mysql/debian.cnf --execute="GRANT ALL PRIVILEGES ON website.* TO website@localhost IDENTIFIED BY 'website'"
    when: create_database_task|success