def site(name, enable=True): env = Environment.get_instance() if enable: Execute("a2ensite %s" % name, command="/usr/sbin/a2ensite %s" % name, notifies=[("restart", env.resources["Service"]["apache2"])], not_if=lambda: os.path.exists("%s/sites-enabled/%s" % (env.config.apache.dir, name)), only_if=lambda: os.path.exists("%s/sites-available/%s" % (env.config.apache.dir, name))) else: Execute("a2dissite %s" % name, command="/usr/sbin/a2dissite %s" % name, notifies=[("restart", env.resources["Service"]["apache2"])], only_if=lambda: os.path.exists("%s/sites-enabled/%s" % (env.config.apache.dir, name)))
def module(name, enable=True, conf=False): env = Environment.get_instance() if conf: env.cookbooks.apache2.config(name) if enable: Execute("a2enmod %s" % name, command="/usr/sbin/a2enmod %s" % name, notifies=[("restart", env.resources["Service"]["apache2"])], not_if=lambda: os.path.exists("%s/mods-enabled/%s.load" % (env.config.apache.dir, name))) else: Execute("a2dismod %s" % name, command="/usr/sbin/a2dismod %s" % name, notifies=[("restart", env.resources["Service"]["apache2"])], only_if=lambda: os.path.exists("%s/mods-enabled/%s.load" % (env.config.apache.dir, name)))
def site(name, enable=True): env = Environment.get_instance() if enable: cmd = 'nxensite' else: cmd = 'nxdissite' def _not_if(): e = exists("%s/sites-enabled/%s" % (env.config.nginx.dir, name)) return e if enable else not e Execute("%s %s" % (cmd, name), command = "/usr/sbin/%s %s" % (cmd, name), notifies = [("reload", env.resources["Service"]["nginx"])], not_if = _not_if)
def setup_ebs_volume(name=None, availability_zone=None, volume_id=None, device=None, linux_device=None, snapshot_id=None, size=None, fstype=None, mount_point=None, fsoptions=None): env = Environment.get_instance() if linux_device is None: linux_device = device env.cookbooks.aws.EBSVolume( name or volume_id, volume_id=volume_id, availability_zone=availability_zone or env.config.aws.availability_zone, device=device, linux_device=linux_device, snapshot_id=snapshot_id, size=size, action="attach" if volume_id else ["create", "attach"]) if fstype: if fstype == "xfs": Package("xfsprogs") Execute( "mkfs.%(fstype)s -f %(device)s" % dict(fstype=fstype, device=linux_device), not_if= """if [ "`file -s %(device)s`" = "%(device)s: data" ]; then exit 1; fi""" % dict(device=linux_device)) if mount_point: Mount(mount_point, device=linux_device, fstype=fstype, options=fsoptions if fsoptions is not None else ["noatime"], action=["mount", "enable"])
if env.system.platform == "ubuntu": ver = env.system.lsb['release'] apt = "deb http://www.serverdensity.com/downloads/linux/debian lenny main" # if ver == "10.04": # apt = "deb http://apt.librato.com/ubuntu/ lucid non-free" elif env.system.platform == "debian": ver = env.system.lsb['release'] apt = "deb http://www.serverdensity.com/downloads/linux/debian lenny main" # if ver == '5.0': # apt = "deb http://apt.librato.com/debian/ lenny non-free" if not apt: raise Fail("Can't find a serverdensity package for your platform/version") Execute("apt-update-serverdensity", command = "apt-get update", action = "nothing") Execute("curl http://www.serverdensity.com/downloads/boxedice-public.key | apt-key add -", not_if = "(apt-key list | grep 'Server Density' > /dev/null)") File(apt_list_path, owner = "root", group ="root", mode = 0644, content = apt+"\n", notifies = [("run", env.resources["Execute"]["apt-update-serverdensity"], True)]) Package("sd-agent") Directory(env.config.serverdensity.plugin_directory,
import os from kokki import Package, Execute, File, Script Package("debconf-utils") Execute("apt-update-java", command="apt-get update", action="nothing") if env.system.lsb['codename'] == 'karmic': def enter_the_multiverse(): with open("/etc/apt/sources.list", "r") as fp: source = fp.read().split(' ')[1] return ( "deb {source} karmic multiverse\n" "deb-src {source} karmic multiverse\n" "deb {source} karmic-updates multiverse\n" "deb-src {source} karmic-updates multiverse\n" "deb http://security.ubuntu.com/ubuntu karmic-security multiverse\n" ).format(source=source) File("/etc/apt/sources.list.d/multiverse.list", owner="root", group="root", mode=0644, not_if=lambda: os.path.exists( "/etc/apt/sources.list.d/multiverse.list"), content=enter_the_multiverse, notifies=[("run", env.resources["Execute"]["apt-update-java"], True)]) if env.system.lsb['codename'] == 'lucid': Execute(
import os from kokki import Execute, File, Package, Service, Template Service("sendmail", supports_restart=True, supports_reload=True, supports_status=True, action="nothing") Package("sasl2-bin") Package("sendmail") Execute("sendmailconfig", command="sendmailconfig --no-reload", action="nothing") Execute("newaliases", command="newaliases", action="nothing") File("/etc/mail/sendmail.mc", owner="root", group="smmsp", mode=0644, content=Template("sendmail/sendmail.mc.j2"), notifies=[("run", env.resources["Execute"]["sendmailconfig"], True), ("restart", env.resources["Service"]["sendmail"])]) File("/etc/mail/submit.mc", owner="root", group="smmsp", mode=0644, content=Template("sendmail/submit.mc.j2"), notifies=[("run", env.resources["Execute"]["sendmailconfig"], True), ("restart", env.resources["Service"]["sendmail"])])
mode=0755, owner="root", group="root", content=StaticFile("apache2/files/apache2_module_conf_generate.pl")) for d in ('sites-available', 'sites-enabled', 'mods-available', 'mods-enabled'): Directory("%s/%s" % (env.config.apache.dir, d), mode=0755, owner="root", group="root") libdir = "lib64" if env.system.architecture == "x86_64" else "lib" Execute( "generate-module-list", command= "/usr/local/bin/apache2_module_conf_generate.pl /usr/%s/httpd/modules /etc/httpd/mods-available" % libdir) # %w{a2ensite a2dissite a2enmod a2dismod}.each do |modscript| # template "/usr/sbin/#{modscript}" do # source "#{modscript}.erb" # mode 0755 # owner "root" # group "root" # end # end # # # installed by default on centos/rhel, remove in favour of mods-enabled # file "#{node[:apache][:dir]}/conf.d/proxy_ajp.conf" do # action :delete
import os from kokki import Package, Directory, Execute, File, Template env.include_recipe("mongodb") env.include_recipe("supervisor") env.cookbooks.supervisor.SupervisorService("avatartare") Package("python-pycurl") Package("python-imaging") # Clone project Directory(os.path.dirname(env.config.avatartare.path), mode=0755) Execute( "git clone git://github.com/samuel/avatartare.git %s" % env.config.avatartare.path, creates=env.config.avatartare.path, ) # Bootstrap the environment Execute( "avatartare-bootstrap", command="python bin/bootstrap.py env", cwd=env.config.avatartare.path, creates="%s/env" % env.config.avatartare.path, ) # Config File("avatartare-local_settings.py", path="%s/local_settings.py" % env.config.avatartare.path, content=Template("avatartare/local_settings.py.j2"),
import os from kokki import Execute, File base_url = "http://aspersa.googlecode.com/svn/trunk/{name}" for name in env.config.aspersa.scripts: path = os.path.join(env.config.aspersa.install_path, name) url = base_url.format(name=name) Execute("wget -q -O {path} {url}".format(path=path, url=url), creates = path) File(path, owner = "root", group = "root", mode = 0755)
from kokki import Package, Service, Execute, File, Template env.include_recipe("librato") Package("librato-silverline") Service("silverline", action="start") Execute("reload-silverline", command = "killall lmd", action = "nothing") File("/etc/load_manager/lmd.conf", owner = "root", group = "root", mode = 0600, content = Template("librato/lmd.conf.j2"), notifies = [("run", env.resources["Execute"]["reload-silverline"])]) File("/etc/load_manager/lmc.conf", owner = "root", group = "root", mode = 0600, content = Template("librato/lmc.conf.j2"))
import json import os import openstack.compute from kokki import Execute, Package, Directory, File, Template, Service apt_list_path = "/etc/apt/sources.list.d/nginx-stable-natty.list" Execute("apt-update-nginx", command="apt-get update", action="nothing") apt = None if env.system.platform == "ubuntu": Package("python-software-properties") Execute("add-apt-repository ppa:nginx/stable", not_if=lambda: os.path.exists(apt_list_path), notifies=[("run", env.resources["Execute"]["apt-update-nginx"], True)]) def get_internal_appnode_ips(): fabric_env = json.loads(env.config.fabric_env) appnode_list = [] compute = openstack.compute.Compute( username=env.config.openstack_compute.username, apikey=env.config.openstack_compute.api_key) if fabric_env["node_type"] == "allinone": appnode_list.append(["127.0.0.1"]) else: for server in compute.servers.list(): if "appnode" in server.name: appnode_list.append(server.addresses["private"][0])
import os from kokki import Execute, Package apt_list_path_pg = "/etc/apt/sources.list.d/pitti-postgresql-natty.list" apt_list_path_gis = "/etc/apt/sources.list.d/ubuntugis-ubuntugis-unstable-natty.list" Execute("apt-update-postgresql9", command="apt-get update", action="nothing") apt = None if env.system.platform == "ubuntu": Package("python-software-properties") Execute("add-apt-repository ppa:pitti/postgresql", not_if = lambda:os.path.exists(apt_list_path_pg), notifies = [("run", env.resources["Execute"]["apt-update-postgresql9"], True)]) Execute("add-apt-repository ppa:ubuntugis/ubuntugis-unstable", not_if = lambda:os.path.exists(apt_list_path_gis), notifies = [("run", env.resources["Execute"]["apt-update-postgresql9"], True)])
from kokki import Directory, Execute, File, Template, Package, Service env.include_recipe("mysql.client") if env.system.platform in ("debian", "ubuntu"): Directory("/var/cache/local/preseeding", owner="root", group="root", mode=0755, recursive=True) Execute( "preseed mysql-server", command= "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed", action="nothing") File("/var/cache/local/preseeding/mysql-server.seed", owner="root", group="root", mode=0600, content=Template("mysql/mysql-server.seed.j2"), notifies=[("run", env.resources["Execute"]["preseed mysql-server"], True)]) File("/etc/mysql/debian.cnf", owner="root", group="root", mode=0600, content=Template("mysql/debian.cnf.j2"))
from kokki import Package, Execute Package("erlang") if env.system.platform in ("ubuntu", "debian"): pkg_url = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.3.1/rabbitmq-server_2.3.1-1_all.deb" Execute("cd /tmp ; wget %s ; dpkg -i %s ; rm rabbitmq*deb" % (pkg_url, pkg_url.rsplit('/', 1)[-1]), not_if="dpkg-query -c rabbitmq-server > /dev/null")
import os from kokki import Package, Execute, File, Script Package("debconf-utils") Execute("apt-update-java", command="apt-get update", action="nothing") if env.system.lsb['codename'] == 'karmic': def enter_the_multiverse(): with open("/etc/apt/sources.list", "r") as fp: source = fp.read().split(' ')[1] return ( "deb {source} karmic multiverse\n" "deb-src {source} karmic multiverse\n" "deb {source} karmic-updates multiverse\n" "deb-src {source} karmic-updates multiverse\n" "deb http://security.ubuntu.com/ubuntu karmic-security multiverse\n" ).format(source=source) File("/etc/apt/sources.list.d/multiverse.list", owner="root", group="root", mode=0644, not_if=lambda: os.path.exists( "/etc/apt/sources.list.d/multiverse.list"), content=enter_the_multiverse, notifies=[("run", env.resources["Execute"]["apt-update-java"], True)]) ubuntu_sources = ("lucid", "maverick")
from kokki import Package, Execute, Mount if env.config.mdadm.arrays: Package("mdadm") Execute("mdadm-update-conf", action="nothing", command=("(" "echo DEVICE partitions > /etc/mdadm/mdadm.conf" "; mdadm --detail --scan >> /etc/mdadm/mdadm.conf" ")")) for arr in env.config.mdadm.arrays: array = arr.copy() fstype = array.pop('fstype', None) fsoptions = array.pop('fsoptions', None) mount_point = array.pop('mount_point', None) env.cookbooks.mdadm.Array(**array) if fstype: if fstype == "xfs": Package("xfsprogs") Execute( "mkfs.%(fstype)s -f %(device)s" % dict(fstype=fstype, device=array['name']), not_if= """if [ "`file -s %(device)s`" = "%(device)s: data" ]; then exit 1; fi""" % dict(device=array['name'])) if mount_point:
from kokki import Package, Execute, File, Fail Package("erlang") apt_list_path = '/etc/apt/sources.list.d/rabbitmq.list' apt = None if env.system.platform in ("ubuntu", "debian"): apt = "deb http://www.rabbitmq.com/debian/ testing main" if not apt: raise Fail("Can't find a rabbitmq package for your platform/version") Execute("apt-update-rabbitmq", command="apt-get update", action="nothing") Execute( "curl http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | apt-key add -", not_if="(apt-key list | grep rabbitmq > /dev/null)") File(apt_list_path, owner="root", group="root", mode=0644, content=apt + "\n", notifies=[("run", env.resources["Execute"]["apt-update-rabbitmq"], True)]) Package("rabbitmq-server")
import os from kokki import Execute, File, Template Execute("pip install newrelic=={0}".format(env.config.newrelic.version)) File("{0}".format(env.config.newrelic.ini_file), content=Template("newrelic/newrelic.ini.j2"), owner="deploy", group="root", mode=0644) File("{0}".format(env.config.newrelic.log_file), content="", owner="deploy", group="root", mode=0644)
apt_list_path = '/etc/apt/sources.list.d/librato.list' apt = None if env.system.platform == "ubuntu": ver = env.system.lsb['release'] if ver == "10.04": apt = "deb http://apt.librato.com/ubuntu/ lucid non-free" elif ver == "10.10": apt = "deb http://apt.librato.com/ubuntu/ maverick non-free" elif env.system.platform == "debian": ver = env.system.lsb['release'] if ver == '5.0': apt = "deb http://apt.librato.com/debian/ lenny non-free" if not apt: raise Fail("Can't find a librato package for your platform/version") Execute("apt-update-librato", command = "apt-get update", action = "nothing") Execute("curl http://apt.librato.com/packages.librato.key | apt-key add -", not_if = "(apt-key list | grep Librato > /dev/null)") File(apt_list_path, owner = "root", group ="root", mode = 0644, content = apt+"\n", notifies = [("run", env.resources["Execute"]["apt-update-librato"], True)])
elif ver == "8.10": apt = "deb http://packages.cloudkick.com/ubuntu intrepid main" elif ver == "8.04": apt = "deb http://packages.cloudkick.com/ubuntu hardy main" elif ver == "6.04": apt = "deb http://packages.cloudkick.com/ubuntu dapper main" elif env.system.platform == "debian": ver = env.system.lsb['release'] apt = "deb http://packages.cloudkick.com/ubuntu lucid main" # if ver == '5.0': # apt = "deb http://apt.librato.com/debian/ lenny non-free" if not apt: raise Fail("Can't find a cloudkick package for your platform/version") Execute("apt-update-cloudkick", command="apt-get update", action="nothing") Execute( "curl http://packages.cloudkick.com/cloudkick.packages.key | apt-key add -", not_if="(apt-key list | grep 'Cloudkick' > /dev/null)") File(apt_list_path, owner="root", group="root", mode=0644, content=apt + "\n", notifies=[("run", env.resources["Execute"]["apt-update-cloudkick"], True) ]) File("/etc/cloudkick.conf", owner="root",
from kokki import Execute, File env.include_recipe("java.jre") apt_list_path = '/etc/apt/sources.list.d/cloudera.list' apt = ("deb http://archive.cloudera.com/debian {distro}-cdh3 contrib\n" "deb-src http://archive.cloudera.com/debian {distro}-cdh3 contrib\n" ).format(distro=env.system.lsb['codename']) Execute("apt-update-clouders", command="apt-get update", action="nothing") Execute( "curl -s http://archive.cloudera.com/debian/archive.key | sudo apt-key add -", not_if="(apt-key list | grep Cloudera > /dev/null)") File(apt_list_path, owner="root", group="root", mode=0644, content=apt, notifies=[("run", env.resources["Execute"]["apt-update-clouders"], True)])
apt_list_path = '/etc/apt/sources.list.d/mongodb.list' apt = None if env.system.platform == "ubuntu": ver = env.system.lsb['release'] if ver in ('10.10', '10.04', '9.10', '9.04'): ver = ver.replace(".0", ".") apt = 'deb http://downloads.mongodb.org/distros/ubuntu %s 10gen' % ver elif env.system.platform == "debian": ver = env.system.lsb['release'] if ver == '5.0': apt = 'deb http://downloads.mongodb.org/distros/debian 5.0 10gen' if not apt: raise Fail("Can't find a mongodb package for your platform/version") Execute("apt-update-mongo", command="apt-get update", action="nothing") Execute("apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10", not_if="(apt-key list | grep 10gen.com > /dev/null)") File(apt_list_path, owner="root", group="root", mode=0644, content=apt + "\n", notifies=[("run", env.resources["Execute"]["apt-update-mongo"], True)]) ### Package("mongodb-stable")
from kokki import Package, File, Execute, Template Package("unattended-upgrades") Execute("update-package-index", command="apt-get -qq update", action="nothing") File("/etc/apt/apt.conf", owner="root", group="root", mode=0644, content=Template("apt/apt.conf.j2")) File("/etc/apt/sources.list", owner="root", group="root", mode=0644, content="%s\n" % "\n".join(env.config.apt.sources), notifies=[("run", env.resources["Execute"]["update-package-index"])])
elif fabric_env["node_type"] == "appbalancer": raise (NotImplementedError) else: for server in compute.servers.list(): if "loadbalancer" in server.name: ip_addresses["loadbalancer_internal_ip"] = server.addresses[ "private"][0] if "appnode" in server.name: ip_addresses["appnode_internal_ips"] = server.addresses[ "private"] return ip_addresses Execute( "iptables-restore", action="nothing", command=( "iptables --flush && /sbin/iptables-restore < /etc/iptables.up.rules"), ) File("/etc/iptables.up.rules", owner="root", group="root", mode=0644, notifies=[("run", env.resources["Execute"]["iptables-restore"], True)], content=Template("iptables/iptables.up.rules.j2", variables=get_openstack_ips())) File("/etc/network/if-pre-up.d/iptables", owner="root", group="root", mode=0644,
from kokki import Execute, File, Package, Service, Template if env.system.platform in ("ubuntu", "debian"): Execute( "wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -", not_if="(apt-key list | grep 'Kohsuke Kawaguchi' > /dev/null)") apt = "deb http://pkg.jenkins-ci.org/debian binary/" apt_list_path = '/etc/apt/sources.list.d/jenkins.list' Execute("apt-update-jenkins", command="apt-get update", action="nothing") File(apt_list_path, owner="root", group="root", mode=0644, content=apt + "\n", notifies=[("run", env.resources["Execute"]["apt-update-jenkins"], True)]) Package("jenkins") Service("jenkins") File("/etc/default/jenkins", owner="root", group="root", mode=0644, content=Template("jenkins/default.j2"), notifies=[("restart", env.resources["Service"]["jenkins"])])