2
0
mirror of https://github.com/frappe/bench.git synced 2025-02-13 08:18:27 +00:00

made ansible idempotent

This commit is contained in:
nginn 2015-12-29 13:45:45 +03:00
parent 242e3c4add
commit b1c2a0cd09
31 changed files with 264 additions and 130 deletions

View File

@ -4,4 +4,4 @@
sudo: true
roles:
- add_repos
- install_packages
- install_n_configure_packages

View File

@ -3,59 +3,93 @@
#- hosts: local
# tasks:
- name: "Transfer script for .repo creation to /tmp"
copy: src=create_mariadb_repo_centos.sh dest=/tmp mode=0777
###### MariaDB repo setup for rpm platforms
- name: "Check if MariaDB repo already added CentOS"
stat: path=/etc/yum.repos.d/mariadb.repo
register: mariadb_repo
when: (ansible_distribution == "CentOS")
- name: "Filling in mariadb.repo file"
command: /tmp/create_mariadb_repo_centos.sh /tmp/mariadb.repo
when: (ansible_distribution == "CentOS")
- name: "Adding MariaDB repo CentOS"
script: ../files/create_mariadb_repo_centos.sh /etc/yum.repos.d/mariadb.repo
when: (ansible_distribution == "CentOS") and mariadb_repo.stat.exists == False
- name: "Place mariadb.repo file in system dir"
command: mv /tmp/mariadb.repo /etc/yum.repos.d/
when: (ansible_distribution == "CentOS")
- name: "Clean files in tmp"
command: rm /tmp/create_mariadb_repo_centos.sh
###### epel & ius installation for CentOS
- name: "Check if epel-release is installed CentOS"
when: (ansible_distribution == "CentOS")
shell: rpm -q epel-release | grep "not installed" | wc -l
register: epel_release_check
- name: "Installing epel rpm for CentOS 6"
yum: name=http://dl.iuscommunity.org/pub/ius/stable/CentOS/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/epel-release-6-5.noarch.rpm state=present
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
- name: "Installing ius rpm for CentOS 6"
yum: name=http://dl.iuscommunity.org/pub/ius/stable/CentOS/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/ius-release-1.0-14.ius.centos6.noarch.rpm state=present
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") and (epel_release_check.stdout == "1")
- name: "Install epel for CentOS 7"
yum: name=epel-release state=present
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7") and (epel_release_check.rc == 1)
- name: "Check if ius is installed on CentOS 6"
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
shell: rpm -q ius-release | grep "not installed" | wc -l
register: ius_rpm_check
- name: "Installing ius rpm for CentOS 6"
yum: name=http://dl.iuscommunity.org/pub/ius/stable/CentOS/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/ius-release-1.0-14.ius.centos6.noarch.rpm state=present
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") and (ius_rpm_check.stdout == "1")
###### install packages required for node.js & mariadb repo installation in Debian/Ubuntu
- name: "Check if software-properties-common is already installed Debian"
shell: dpkg-query -W software-properties-common | grep "no packages found" | wc -l
when: (ansible_distribution == "Debian")
register: spc_installed
- name: "Install software properties Debian"
apt: name=software-properties-common
when: (ansible_distribution == "Debian") and (spc_installed.stdout == "1")
- name: "Check if python-software-properties is already installed Debian"
shell: dpkg-query -W python-software-properties | grep "no packages found" | wc -l
ignore_errors: yes
when: (ansible_distribution == "Debian")
register: psp_installed
- name: "Install python software properties Debian"
apt: name=python-software-properties
when: (ansible_distribution == "Debian") and (psp_installed.stdout == "1")
- name: "Check if MariaDB key is already installed Debian/Ubuntu"
shell: apt-key list | grep "package-signing-key@mariadb.org" | wc -l
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")
register: mariadb_key_installed
- name: "Receive MariaDB key Debian/Ubuntu"
apt_key: keyserver=keyserver.ubuntu.com id=0xcbcb082a1bb943db
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu") and (mariadb_key_installed.stdout == "0")
- name: "Check if MariaDB repo is already added Debian/Ubuntu"
shell: find /etc/apt/ -name *.list | xargs cat | grep ^[[:space:]]*deb | grep -i mariadb | wc -l
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")
register: mariadb_repo_deb
- name: "Add MariaDB repo Debian"
apt_repository: repo="deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/debian {{ ansible_distribution_release }} main" update_cache=yes
when: (ansible_distribution == "Debian" and ansible_distribution_major_version >= 6) and (mariadb_repo_deb.stdout == "0")
- name: "Add MariaDB repo Ubuntu"
apt_repository: repo="deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu {{ ansible_distribution_release }} main" update_cache=yes
when: (ansible_distribution == "Ubuntu") and (mariadb_repo_deb.stdout == "0")
- name: "Check if Nodesource repo is already added Debian"
shell: find /etc/apt/ -name *.list | xargs cat | grep ^[[:space:]]*deb | grep -i node | wc -l
when: (ansible_distribution == "Debian")
register: nodesource_repo
- name: "Install Nodesource Node.js repo Debian"
shell: curl -sL https://deb.nodesource.com/setup_0.12 | bash -
when: (ansible_distribution == "Debian") and (nodesource_repo.stdout == 0)
- name: "Update repository cache Debian/Ubuntu"
apt: update_cache=yes
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")
- name: "Install software properties Debian"
apt: name=software-properties-common
when: (ansible_distribution == "Debian")
- name: "Install python software properties Debian"
apt: name=python-software-properties
when: (ansible_distribution == "Debian")
- name: "Receive key Debian/Ubuntu"
apt_key: keyserver=keyserver.ubuntu.com id=0xcbcb082a1bb943db
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")
- name: "Add MariaDB repo Debian"
apt_repository: repo="deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/debian {{ ansible_distribution_release }} main"
when: (ansible_distribution == "Debian" and ansible_distribution_major_version >= 6)
- name: "Add MariaDB repo Ubuntu"
apt_repository: repo="deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu {{ ansible_distribution_version }} main"
when: (ansible_distribution == "Ubuntu")
- name: "Install Nodesource Node.js repo Debian"
shell: curl -sL https://deb.nodesource.com/setup_0.12 | bash -
when: (ansible_distribution == "Debian")

View File

@ -0,0 +1,4 @@
#!/bin/bash
res=$(chkconfig | grep $1 | awk 'BEGIN {RS = ":"}; {print $0}' | grep `runlevel | cut -d" " -f2` | grep on | wc -l)
echo -n $res

View File

@ -0,0 +1,4 @@
#!/bin/bash
debconf-set-selections <<< "postfix postfix/mailname string `hostname`"

View File

@ -0,0 +1,3 @@
#!/bin/bash
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"

View File

@ -0,0 +1,3 @@
#!/bin/bash
debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password $1"
debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password $1"

View File

@ -0,0 +1,40 @@
---
- name: "Check if supervisor is already added in services CentOS6"
script: ../files/check_if_service_is_on.sh supervisord
register: supervisor_service
- name: "Add supervisord as a service CentOS6"
command: chkconfig --add supervisord
when: (supervisor_service.stdout == "0")
- name: "Check if redis service is on CentOS6"
script: ../files/check_if_service_is_on.sh redis
register: redis_is_on
- name: "Set redis service on CentOS6"
shell: chkconfig redis on
when: (redis_is_on.stdout == "0")
- name: "Check if mysql service is on CentOS6"
script: ../files/check_if_service_is_on.sh mysql
register: mysql_is_on
- name: "Set mysql service on CentOS6"
shell: chkconfig mysql on
when: (mysql_is_on.stdout == "0")
- name: "Check if nginx service is on CentOS6"
script: ../files/check_if_service_is_on.sh nginx
register: nginx_is_on
- name: "Set nginx service on CentOS6"
shell: chkconfig nginx on
when: (nginx_is_on.stdout == "0")
- name: "Check if supervisord service is on CentOS6"
script: ../files/check_if_service_is_on.sh supervisord
register: supervisord_is_on
- name: "Set supervisord service on CentOS6"
shell: chkconfig supervisord on
when: (supervisord_is_on.stdout == "0")

View File

@ -0,0 +1,22 @@
---
- name: "Generate frappe password"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: frappe_pass
- name: "Generate password for MariaDB"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: msq_pass
- name: "Generate administrator password"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: admin_pass
- name: "Save frappe password"
shell: echo "frappe password:" > ~/frappe_passwords.sh {{frappe_pass.stdout}} >> ~/frappe_passwords.txt
- name: "Save MariaDB root password"
shell: echo "MariaDB root password:" >> ~/frappe_passwords.sh {{msq_pass.stdout}} >> ~/frappe_passwords.txt
- name: "Save administrator password"
shell: echo "administrator password:" >> ~/frappe_passwords.sh {{admin_pass.stdout}} >> ~/frappe_passwords.txt

View File

@ -1,7 +1,7 @@
---
- name: "Install packages list for CentOS 6"
yum: pkg={{ item }} state=installed
yum: pkg={{ item }} state=present
with_items:
- git
- MariaDB-server

View File

@ -1,7 +1,7 @@
---
- name: "Install packages list for CentOS 7"
yum: pkg={{ item }} state=installed
yum: pkg={{ item }} state=present
with_items:
- git
- mariadb-server

View File

@ -2,7 +2,7 @@
- name: "Install list of common packages for Debian/Ubuntu"
apt: pkg={{ item }} state=installed
apt: pkg={{ item }} state=present update_cache=yes
with_items:
- python-dev
- python-setuptools

View File

@ -1,7 +1,7 @@
---
- name: "Install packages for Debian 8"
apt: pkg={{ item }} state=installed
apt: pkg={{ item }} state=present
with_items:
- libtiff5-dev
- libjpeg62-turbo-dev

View File

@ -1,7 +1,7 @@
---
- name: "Install packages for Ubuntu/Debian except from Precise and 8"
apt: pkg={{ item }} state=installed
apt: pkg={{ item }} state=present
with_items:
- libtiff5-dev
- libjpeg8-dev

View File

@ -1,7 +1,7 @@
---
- name: "Install packages for Ubuntu Precise Pangolin"
apt: pkg={{ item }} state=installed
apt: pkg={{ item }} state=present
with_items:
- libtiff4-dev
- libjpeg8-dev

View File

@ -0,0 +1,51 @@
---
- name: "Check if supervisor is already installed CentOS 6"
shell: rpm -q supervisor | grep "not installed" | wc -l
register: supervisor_installed
- name: "easy_install supervisor CentOS 6"
shell: easy_install supervisor
when: (supervisor_installed.stdout == "1")
- name: "Check if supervisor init config already exists"
stat: path=/etc/init.d/supervisord
register: init_supervisor
- name: "Fill in supervisor init config"
shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-init-jkoppe > /etc/init.d/supervisord
when: (init_supervisor.stat.exists == False)
- name: "Check if supervisor sysconfig already exists"
stat: path=/etc/sysconfig/supervisord
register: sysconfig_supervisor
- name: "Fill in supervisor sysconfig"
shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-sysconfig-jkoppe > /etc/sysconfig/supervisord
when: (sysconfig_supervisor.stat.exists == False)
- name: "Check if supervisor etc conf already exists"
stat: path=/etc/supervisord.conf
register: etc_supervisor
- name: "Fill in supervisor etc conf"
shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/supervisord.conf > /etc/supervisord.conf
when: (etc_supervisor.stat.exists == False)
- name: "Check if supervisor.d already exists"
stat: path=/etc/supervisor.d
register: supervisor_d
- name: "Create supervisor.d"
shell: mkdir /etc/supervisor.d
when: (supervisor_d.stat.exists == False)
- name: "Check attributes of /etc/init.d/supervisord"
stat: path=/etc/init.d/supervisord
register: init_supervisor_file
- name: "Set /etc/init.d/supervisord executable"
shell: chmod +x /etc/init.d/supervisord
when: (init_supervisor_file.stat.xoth == False or init_supervisor_file.stat.xusr == False or init_supervisor_file.stat.xgrp == False)
- name: "Start supervisord service CentOS6"
shell: service supervisord start || true

View File

@ -1,31 +1,17 @@
---
# tasks file for install_packages
- name: "Check if there is already frappe_passwords.sh file"
stat: path=/root/frappe_passwords.sh
register: passwords_exist
- name: "Generate frappe password"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: frappe_pass
- include: generate_passwords.yml
when: passwords_exist.stat.exists == False
- name: "Generate password for MariaDB"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: msq_pass
- name: "Generate administrator password"
shell: echo `cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 16`
register: admin_pass
- name: "Save frappe password"
shell: echo "frappe password:" > ~/frappe_passwords.txt {{frappe_pass.stdout}} >> ~/frappe_passwords.txt
- name: "Save MariaDB root password"
shell: echo "MariaDB root password:" >> ~/frappe_passwords.txt {{msq_pass.stdout}} >> ~/frappe_passwords.txt
- name: "Save administrator password"
shell: echo "administrator password:" >> ~/frappe_passwords.txt {{admin_pass.stdout}} >> ~/frappe_passwords.txt
- include: setup_debconf.yml
when: (ansible_distribution == "Debian")
###### Install bunch of packages
- include: install_packages_deb.yml
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")
@ -55,6 +41,7 @@
- include: install_supervisor_centos6.yml
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
###### Configure & launch services
- include: configure_services_centos6.yml
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
@ -67,15 +54,31 @@
- include: start_services_centos7.yml
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
- include: configure_mariadb_deb.yml
- name: "Check if need to configure MariaDB Debian"
stat: path=/etc/mysql/conf.d/barracuda.cnf
register: mariadb_configuration_deb
when: (ansible_distribution == "Debian")
- include: configure_mariadb_cent.yml
- name: "Create MariaDB configuration Debian"
script: ../files/create_mariadb_config.sh /etc/mysql/conf.d/barracuda.cnf
when: (ansible_distribution == "Debian") and (mariadb_configuration_deb.stat.exists == False)
- name: "Check if need to configure MariaDB CentOS"
stat: path=/etc/my.cnf.d/barracuda.cnf
register: mariadb_configuration_cent
when: (ansible_distribution == "CentOS")
- name: "Restart MariaDB service CentOS"
when: (ansible_distribution == "CentOS")
- name: "Create MariaDB configuration CentOS"
script: ../files/create_mariadb_config.sh /etc/my.cnf.d/barracuda.cnf
when: (ansible_distribution == "CentOS") and (mariadb_configuration_cent.stat.exists == False)
- name: "Restart MariaDB service CentOS7"
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
service: name=mariadb state=restarted
- name: "Restart MariaDB service CentOS6"
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")
service: name=mysql state=restarted
- name: "Restart MariaDB service Debian/Ubuntu"
when: (ansible_distribution == "Debian" or ansible_distribution == "Ubuntu")

View File

@ -0,0 +1,25 @@
---
- name: "Check if postfix hostname is already configured"
shell: debconf-show postfix | grep mailname | wc -l
register: postfix_mailname
- name: "Debconf postfix hostname"
script: ../files/debconf_postfix_mailname.sh
when: (postfix_mailname.stdout == "0")
- name: "Check if postfix main_mailer_type is already configured"
shell: debconf-show postfix | grep main_mailer_type | wc -l
register: postfix_main_mailer_type
- name: "Debconf postfix main_mailer_type"
script: ../files/debconf_postfix_main_mailer.sh
when: (postfix_main_mailer_type.stdout == "0")
- name: "Check if MariaDB password is already configured"
shell: debconf-show mariadb-server-5.5 | grep "password" | wc -l
register: pass_configured
- name: "Debconf MariaDB password"
script: ../files/set_mariadb_password.sh {{ msq_pass }}
when: (pass_configured.stdout == "0")

View File

@ -2,6 +2,6 @@
- service: name=nginx state=started
- service: name=mariadb state=started
- service: name=mysql state=started
- service: name=redis state=started

View File

@ -1,7 +0,0 @@
---
- name: "Transfer script to tmp"
copy: src=create_mariadb_config.sh dest=/tmp mode=0777
- name: "Create MariaDB configuration"
command: /tmp/create_mariadb_config.sh /etc/my.cnf.d/barracuda.cnf

View File

@ -1,8 +0,0 @@
---
- name: "Transfer script to tmp"
copy: src=create_mariadb_config.sh dest=/tmp mode=0777
- name: "Create MariaDB configuration"
command: /tmp/create_mariadb_config.sh /etc/mysql/conf.d/barracuda.cnf

View File

@ -1,11 +0,0 @@
---
- shell: chkconfig --add supervisord
- shell: chkconfig redis on
- shell: chkconfig mysql on
- shell: chkconfig nginx on
- shell: chkconfig supervisord on

View File

@ -1,17 +0,0 @@
---
- name: "easy_install suprevisor CentOS 6"
command: easy_install supervisor
- shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-init-jkoppe > /etc/init.d/supervisord
- shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/redhat-sysconfig-jkoppe > /etc/sysconfig/supervisord
- shell: curl -Ss https://raw.githubusercontent.com/pdvyas/supervisor-initscripts/master/supervisord.conf > /etc/supervisord.conf
- shell: mkdir /etc/supervisor.d
- shell: chmod +x /etc/init.d/supervisord
- name: "Start supervisord service CentOS6"
shell: service supervisord start || true

View File

@ -1,12 +0,0 @@
---
- name: "Debconf postfix"
command: debconf-set-selections <<< "postfix postfix/mailname string `hostname`" debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
environment:
DEBIAN_FRONTEND: noninteractive
- name: "Debconf MariaDB"
command: debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password {{ msq_pass }}" debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password {{ msq_pass }}"
environment:
DEBIAN_FRONTEND: noninteractive