python - In Fabric, how can I check if a Debian or Ubuntu package exists and install it if it does not? -
python - In Fabric, how can I check if a Debian or Ubuntu package exists and install it if it does not? -
i required install memcached part of fabric script setting test servers. figured i'd record here future reference.
pieced superuser comment , stackoverflow answer. (note: i'm running root
rather using sudo
):
def package_installed(pkg_name): """ref: http:superuser.com/questions/427318/#comment490784_427339""" cmd_f = 'dpkg-query -l "%s" | grep -q ^.i' cmd = cmd_f % (pkg_name) settings(warn_only=true): result = run(cmd) homecoming result.succeeded def yes_install(pkg_name): """ref: http://stackoverflow.com/a/10439058/1093087""" run('apt-get --force-yes --yes install %s' % (pkg_name)) def make_sure_memcached_is_installed_and_running(): if not package_installed('memcached'): yes_install('memcached') settings(warn_only=true): run('/etc/init.d/memcached restart', pty=false)
python ubuntu debian fabric
Comments
Post a Comment