-
Notifications
You must be signed in to change notification settings - Fork 3
/
opendcim.yaml
116 lines (101 loc) · 4.08 KB
/
opendcim.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
- name: Configure webserver with apache2
hosts: default
vars_files:
- vars/main.yml
roles:
- { role: geerlingguy.apache }
become: True
tasks:
- name: enable ubuntu multiuniverse
command: apt-add-repository multiverse
- name: update all
apt: upgrade=dist update_cache=yes
- name: install packages
apt: name={{item}} update_cache=yes
with_items:
- apache2
- php7.0
- php7.0-snmp
- php7.0-mysql
- php7.0-mbstring
- php7.0-xml
- libapache2-mod-php7.0
- mysql-server
- apache2-utils
- git
- python-mysqldb #required by ansible mysql_db module
- python-passlib
- snmp
- snmp-mibs-downloader # required for Online Repository module
- php7.0-curl # required Online Repository
- graphviz # required for Network Map report
- name: fix snmp config
lineinfile: dest=/etc/snmp/snmp.conf state=absent regexp='^mibs'
- name: enable apache modules
apache2_module: state=present name=rewrite
notify:
- restart apache2
- name: Check if OpenDCIM code is already cloned
stat:
path: /var/www/vhosts/opendcim
register: varwww
- name: Clone OpenDCIM git repo to /var/www/opendcim
git: repo=https://github.com/samilliken/openDCIM.git dest=/var/www/vhosts/opendcim version={{opendcim_version}} force=yes
when: varwww.stat.exists == False
- name: Fix permissions
file:
path: /var/www/vhosts/opendcim
owner: www-data
group: www-data
recurse: yes
- name: Copy db.inc.php-dist
command: mv /var/www/vhosts/opendcim/db.inc.php-dist /var/www/vhosts/opendcim/db.inc.php
when: varwww.stat.exists == False
- name: Create htaccess file
template: src=templates/htaccess.j2 dest=/var/www/vhosts/opendcim/.htaccess
- name: Create htpasswd file
htpasswd: path=/var/www/users name={{webuser}} password={{webpassword}}
- name: Put database variables
replace: dest=/var/www/vhosts/opendcim/db.inc.php regexp="\$dbhost = \'localhost\';" replace='$dbhost = "{{databaseip}}";'
- name: Put database variables
replace: dest=/var/www/vhosts/opendcim/db.inc.php regexp="\$dbname = \'dcim\';" replace='$dbname = "{{databasename}}";'
- name: Put database variables
replace: dest=/var/www/vhosts/opendcim/db.inc.php regexp="\$dbuser = \'dcim\';" replace='$dbuser = "{{databaseuser}}";'
- name: Put database variables
replace: dest=/var/www/vhosts/opendcim/db.inc.php regexp="\$dbpass = \'dcim\';" replace='$dbpass = "{{databasepassword}}";'
- name: Download mibs
command: download-mibs
- name: Mysql config
lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
insertafter: '\[mysqld\]'
line: " sql_mode=\"\" "
notify:
- restart mysql
- name: Set root user password
mysql_user: name=root
host="127.0.0.1"
password="{{ databasepassword }}"
check_implicit_admin=yes
state=present
- name: Create database user
mysql_user: host="127.0.0.1" login_user=root login_password='' name={{databaseuser}} password={{databasepassword}} priv={{databasename}}.*:ALL,GRANT state=present
- name: Create database
mysql_db: login_host="127.0.0.1" name={{databasename}} login_user={{databaseuser}} login_password={{databasepassword}} state=present
- name: Upload database backup
copy: src=dump.sql.bz2 dest=/tmp
ignore_errors: yes
notify:
- Load database backup
handlers:
- name: restart apache2
shell: systemctl restart apache2.service
- name: restart mysql
shell: systemctl restart mysql.service
- name: Load database backup
mysql_db: login_host="127.0.0.1" name={{databasename}} login_user={{databaseuser}} login_password={{databasepassword}} state=import target=/tmp/dump.sql.bz2
notify:
- delete install.php file
- name: delete install.php file
file: path=/var/www/vhosts/opendcim/install.php state=absent