Skip to content

Commit 4fca433

Browse files
committedOct 10, 2013
Initial version
1 parent 3882ded commit 4fca433

8 files changed

+351
-1
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
*.pyc
3+
4+
config.py

‎README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
azimut-deploy
22
=============
33

4-
Azimut's fabric scripts
4+
Azimut's fabric scripts. MIT license.
5+
6+
To be used with azimut-gestion tool !
7+
8+
## Setup
9+
10+
Copy `config.py.dist` to `config.py` and edit values if needed.
11+
12+
Some scripts except configuration files (for vim, zsh, etc.), who should be in the `AZIMUT_CONFIG` folder. You can find our files (https://github.com/Azimut-Prod/azimut-config)[here].
13+
14+
## Scripts available
15+
16+
### server
17+
18+
The main task to setup a server is `server.setup`. You can execute special tasks, use `fab --list` for the full list.
19+
20+
`Zsh` is used for the default shell. The setup script try to install the keymanager, a tool from azimut-gestion. You can skip this part if you don't want to use it.
21+
22+
For all details, check documentation of azimut-gestion !
23+
24+
### owncloud
25+
26+
Can be used to quickly setup an owncloud server. Use `fab owncloud.setup_owncloud` to setup a new server. Sub tasks of the setup can be executed, use `fab --list` to get the full list.

‎config.py.dist

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SSH_KEY = '~/.ssh/id_rsa'
2+
3+
AZIMUT_CONFIG = '../azimut-config/'

‎fabfile.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fabric.api import *
2+
3+
output.stdout = True
4+
5+
# Config
6+
import config
7+
8+
env.key_filename = config.SSH_KEY
9+
10+
11+
# Import server tools
12+
import server
13+
14+
# Import owncloud deployement tools
15+
import owncloud

‎files/owncloud/owncloud.conf

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<VirtualHost *:80>
2+
ServerAdmin webmaster@localhost
3+
4+
DocumentRoot /var/www/owncloud/
5+
<Directory />
6+
Options FollowSymLinks
7+
AllowOverride None
8+
</Directory>
9+
<Directory /var/www/owncloud/>
10+
Options Indexes FollowSymLinks MultiViews
11+
AllowOverride all
12+
Order allow,deny
13+
allow from all
14+
</Directory>
15+
16+
ErrorLog ${APACHE_LOG_DIR}/error.log
17+
18+
# Possible values include: debug, info, notice, warn, error, crit,
19+
# alert, emerg.
20+
LogLevel warn
21+
22+
CustomLog ${APACHE_LOG_DIR}/access.log combined
23+
24+
</VirtualHost>
25+
26+
## SSL
27+
28+
<VirtualHost *:443>
29+
ServerAdmin webmaster@localhost
30+
31+
DocumentRoot /var/www/owncloud/
32+
<Directory />
33+
Options FollowSymLinks
34+
AllowOverride None
35+
</Directory>
36+
<Directory /var/www/owncloud/>
37+
Options Indexes FollowSymLinks MultiViews
38+
AllowOverride all
39+
Order allow,deny
40+
allow from all
41+
</Directory>
42+
43+
ErrorLog ${APACHE_LOG_DIR}/error.log
44+
45+
# Possible values include: debug, info, notice, warn, error, crit,
46+
# alert, emerg.
47+
LogLevel warn
48+
49+
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
50+
51+
# SSL Engine Switch:
52+
# Enable/Disable SSL for this virtual host.
53+
SSLEngine on
54+
55+
# A self-signed (snakeoil) certificate can be created by installing
56+
# the ssl-cert package. See
57+
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
58+
# If both key and certificate are stored in the same file, only the
59+
# SSLCertificateFile directive is needed.
60+
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
61+
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
62+
63+
64+
<FilesMatch "\.(cgi|shtml|phtml|php)$">
65+
SSLOptions +StdEnvVars
66+
</FilesMatch>
67+
<Directory /usr/lib/cgi-bin>
68+
SSLOptions +StdEnvVars
69+
</Directory>
70+
71+
BrowserMatch "MSIE [2-6]" \
72+
nokeepalive ssl-unclean-shutdown \
73+
downgrade-1.0 force-response-1.0
74+
# MSIE 7 and newer should be able to use keepalive
75+
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
76+
77+
</VirtualHost>

‎files/updateKeys.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
SERVER='%(server)s'
4+
USERS="%(users)s"
5+
6+
baseURL='http://XXX/keymanager/servers/getKeys/'
7+
8+
for usr in $USERS; do
9+
10+
homedir=`eval "echo ~$usr"`
11+
12+
13+
wget -O $homedir/.ssh/authorized_keys2.temp -o /dev/null $baseURL$SERVER/$usr/
14+
echo "" >> $homedir/.ssh/authorized_keys2.temp
15+
16+
17+
if grep -q AUTOMATIQUE $homedir/.ssh/authorized_keys2.temp
18+
then
19+
mv $homedir/.ssh/authorized_keys2.temp $homedir/.ssh/authorized_keys2
20+
fi
21+
22+
done

‎owncloud.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from fabric.api import *
2+
from fabric.contrib.files import upload_template
3+
4+
#import time
5+
#import config
6+
7+
@task
8+
def setup_owncloud():
9+
"""Install a new owncloud server"""
10+
11+
execute(setup_repo)
12+
execute(install)
13+
execute(configure_locale)
14+
execute(configure_apache)
15+
16+
@task
17+
def setup_repo():
18+
"""Setup the owncloud repository"""
19+
20+
sudo("echo 'deb http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_7.0/ /' >> /etc/apt/sources.list.d/owncloud.list")
21+
sudo("wget http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_7.0/Release.key -O - | apt-key add -")
22+
sudo("apt-get -y update")
23+
24+
@task
25+
def install():
26+
"""Install the owncloud package and his depencencies"""
27+
sudo("apt-get -y install apache2 php5 php5-gd php-xml-parser php5-intl php5-mysql smbclient curl libcurl3 php5-curl owncloud")
28+
29+
30+
@task
31+
def configure_locale():
32+
"""Configure locales for VM without"""
33+
sudo("echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen")
34+
sudo("locale-gen")
35+
36+
@task
37+
def configure_apache():
38+
"""Configure apache to work with owncloud"""
39+
40+
# Disable default site
41+
sudo("a2dissite 000-default")
42+
43+
# Enable needed apache modules
44+
sudo("a2enmod rewrite")
45+
sudo("a2enmod headers")
46+
sudo("a2enmod ssl")
47+
48+
# Copy config
49+
put('files/owncloud/owncloud.conf', '/etc/apache2/sites-available/')
50+
51+
# Enable site
52+
sudo("a2ensite owncloud.conf")
53+
54+
# Restart apache
55+
sudo("service apache2 restart")

‎server.py

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
from fabric.api import *
2+
from fabric.contrib.files import upload_template
3+
4+
import time
5+
import config
6+
7+
8+
@task
9+
def uname():
10+
"""Execute uname"""
11+
run("uname -a")
12+
13+
14+
@task
15+
def upgrade():
16+
"""Upgrade a sever"""
17+
sudo("apt-get update -y")
18+
sudo("apt-get upgrade -y")
19+
sudo("apt-get dist-upgrade -y")
20+
21+
@task
22+
def install_sudo():
23+
"""Install the sudo programm. Need to be runned with root"""
24+
run("apt-get update")
25+
run("apt-get install -y sudo")
26+
27+
28+
@task
29+
def reboot():
30+
"""Reboot a machine"""
31+
x = 5
32+
while x > 0:
33+
print "Rebooting", env.host, "in", x, "seconds..."
34+
time.sleep(1)
35+
x -= 1
36+
sudo("reboot")
37+
38+
@task
39+
def shutdown():
40+
"""Shutdown a machine"""
41+
x = 5
42+
while x > 0:
43+
print "Shutdowning", env.host, "in", x, "seconds..."
44+
time.sleep(1)
45+
x -= 1
46+
sudo("halt")
47+
48+
49+
@task
50+
def copy_key_manager():
51+
"""Copy the script for keymanagement [$AG:NeedKM]"""
52+
53+
if not hasattr(env, 'keymanagerName') or env.keymanagerName == '':
54+
print "No keymanager name !"
55+
return
56+
57+
upload_template('files/updateKeys.sh', '/root/updateKeys.sh', {
58+
'server': env.keymanagerName,
59+
'users': env.keyManagerUsers,
60+
}, use_sudo=True)
61+
62+
sudo("chmod +x /root/updateKeys.sh")
63+
64+
65+
@task
66+
def cron_key_manager():
67+
"""Install the crontab for the keymanagement"""
68+
sudo('touch /tmp/crondump')
69+
with settings(warn_only=True):
70+
sudo('crontab -l > /tmp/crondump')
71+
sudo('echo " 42 * * * * /root/updateKeys.sh" >> /tmp/crondump')
72+
sudo('crontab /tmp/crondump')
73+
74+
75+
@task
76+
def setup_key_manager():
77+
"""Setup the key manager [$AG:NeedKM]"""
78+
run('mkdir -p ~/.ssh/')
79+
sudo('apt-get install -y ca-certificates')
80+
copy_key_manager()
81+
cron_key_manager()
82+
execute_key_manger()
83+
84+
85+
@task
86+
def execute_key_manger():
87+
"""Execute the keyManager"""
88+
sudo("/root/updateKeys.sh")
89+
90+
91+
@task
92+
def copy_config():
93+
"""Copy config files"""
94+
95+
put(config.AZIMUT_CONFIG + '/.vim*', '~')
96+
put(config.AZIMUT_CONFIG + '/.screenrc', '~')
97+
put(config.AZIMUT_CONFIG + '/.zshrc', '~')
98+
99+
@task
100+
def copy_user_config():
101+
"""Copy the config for a user [$AG:NeedUser]"""
102+
103+
if not hasattr(env, 'fab_user') or env.fab_user == '':
104+
return
105+
106+
put(config.AZIMUT_CONFIG + '/.vim*', '/home/' + env.fab_user + '/')
107+
put(config.AZIMUT_CONFIG + '/.screenrc', '/home/' + env.fab_user + '/')
108+
put(config.AZIMUT_CONFIG + '/.zshrc-user', '/home/' + env.fab_user + '/.zshrc')
109+
110+
111+
@task
112+
def install_base_progs():
113+
"""Install base programms"""
114+
115+
sudo('apt-get install -y zsh screen vim')
116+
117+
118+
@task
119+
def switch_shell_to_zsh():
120+
"""Change the shell to ZSH"""
121+
run('chsh -s /bin/zsh')
122+
123+
@task
124+
def install_rsync():
125+
"""Install rsync"""
126+
sudo("apt-get install rsync")
127+
128+
@task
129+
def add_gestion_for_self_vms():
130+
"""Add a host for it2d vm so they can access the server [$AG:NeedGestion]"""
131+
132+
if not hasattr(env, 'gestion_ip') or env.gestion_ip == '':
133+
return
134+
sudo('echo "' + env.gestion_ip + ' ' + env.gestion_name + '" >> /etc/hosts')
135+
136+
@task
137+
def setup():
138+
"""Setup a new server [$AG:NeedKM][$AG:NeedGestion]"""
139+
140+
execute(install_sudo)
141+
execute(upgrade)
142+
execute(install_base_progs)
143+
execute(add_gestion_for_self_vms)
144+
execute(copy_config)
145+
execute(switch_shell_to_zsh)
146+
execute(install_rsync)
147+
148+
if not hasattr(env, 'keymanagerName') or env.keymanagerName == '':
149+
prompt("Key manager name ?", 'keymanagerName')
150+
prompt("Key manager users ?", 'keyManagerUsers', 'root')
151+
152+
execute(setup_key_manager)

0 commit comments

Comments
 (0)
Please sign in to comment.