我们在POV使用的织物助手
pov-fabric-helpers的Python项目详细描述
织物助手
这是我们在fabric脚本中使用的帮助程序的集合。他们主要是 打算管理ubuntu服务器(12.04 LTS或14.04 LTS)。
内容
-
织物助手
- 帮助者(aka我为什么想要这个?)
- 实例管理api
- 用法
- 作为git子模块使用
- 使用vagrant测试fabfiles
- 0.3(2016-09-11)
- 0.2(2015-08-06)
- 0.1(2014-11-19)
帮助者(也就是我为什么想要这个?)
apt包:
- 确保apt_not_过时() -每天最多运行一次apt get更新。
- 安装软件包("vim 屏幕 基本构建")
- 安装缺少的软件包("vim 屏幕 基本构建")
- 如果没有安装的包('git'):..
- 如果没有可用的包('pov-admin-helpers'):…
用户帐户:
- 确保用户("myusername")
- 确保已知主机("example.com" ssh rsa aaa….")
地区设置:
- 确保语言环境("en", "lt")
文件和目录:
- 确保目录("/srv/data",模式=0o700)
- 上传文件('crontab', '/etc/cron.d/mycrontab')
- 生成_文件('crontab.in', '/etc/cron.d/mycrontab',上下文,使用_jinja=true)
- 下载_文件('/home/user/.ssh/authorized_keys', 'https://example.com/ssh.pubkey')
- git_clone("git@github.com:programmersofvilnius/project.git", "/opt/project")
- Git_更新("/opt/project")
PostgreSQL:
- 确保"PostgreSQL"用户("用户名")
- 确保_postgresql_db("dbname", "owner")
阿帕奇:
- 确保使用SSL密钥(…)
- 安装apache网站('apache.conf.in', 'example.com',上下文,使用'u jinja=true, 模块'ssl 重写代理服务器'u http')`
后缀:
- 安装后缀虚拟表('virtual', '/etc/postfix/virtual.example.com')`
- 将后缀设为public()
在/root/changelog中保存变更日志(需要 /usr/sbin/new changelog entry from pov管理工具 )
- 变更日志("安装材料")
- 变更日志附加(" 更多内容")
- 变更日志横幅("安装内容")
- 运行和更改日志("apt get 安装资料")
另外,许多其他助手都有 changelog 和/或 changelog\u append 隐式调用这些参数的参数。
实例管理api
我的所有fabfile都可以管理特定服务的多个 实例。 从外部看,这看起来像
fab instance1 task1 task2 instance2 task3
它在实例instance1上执行fabric任务 task1 和 task2 然后在 实例2上执行 任务3
实例定义各种参数,例如
- 哪个服务器托管它
- 它在文件系统中的位置
- 使用了哪些Unix用户ID
- 此实例使用的数据库是什么
- 等
为了方便这一点,pov_织物提供了三种功能:
一个 实例 类,应该对其进行子类化以提供您自己的实例
frompov_fabricimportInstanceasBaseInstanceclassInstance(BaseInstance):def__init__(self,name,host,home='/opt/sentry',user='sentry',dbname='sentry'):super(Instance,self).Instance.__init__(name,host)self.home=homeself.user=userself.dbname=dbname
因为这有点重复,所以有一个助手
frompov_fabricimportInstanceasBaseInstanceInstance=BaseInstance.with_params(home='/opt/sentry',user='sentry',dbname='sentry',)
这相当于原始的手动子类化。
(顺便说一下,您也可以通过这种方式添加没有合理默认值的参数,例如 baseinstance.with_params(user=baseinstance.required) )
一个定义新实例和 创建用于选择它们的任务
Instance.define(name='testing',host='root@vagrantbox',)Instance.define(name='production',host='server1.pov.lt',)Instance.define(name='staging',host='server1.pov.lt',home='/opt/sentry-staging',user='sentry-staging',dbname='sentry-staging',)
(顺便说一句,您还可以用 实例定义别名。define\u alias('prod', '生产') )
返回当前选定实例的函数 (如果用户没有选择,则会因错误而中止)
frompov_fabricimportget_instance@taskdeflook_around():instance=get_instance()withsettings(host_string=instance.host):run('hostname')
以前,我使用的命令样式略有不同
fab task1:instance1 task2:instance1 task3:instance2
如果您像这样编写任务,仍然可以支持此功能
@taskdeflook_around(instance=None):instance=get_instance(instance)withsettings(host_string=instance.host):run('hostname')
如果您混合样式,请小心,例如
fab instance1 task1 task2:instance2 task3
将运行 task1 和 task3 on instance1 并且将运行 task2 on 实例2
用法
从pypi获取最新版本:
pip install pov-fabric-helpers
然后在fabfile.py中导入所需的帮助程序
fab instance1 task1 task2 instance2 task30
作为git子模块使用
您可以将此存储库添加为git子模块
fab instance1 task1 task2 instance2 task31
在fabfile.py中添加
fab instance1 task1 task2 instance2 task32
用流浪者测试fabfiles
我不知道你的情况,但我从来没能写出一个fabfile.py 第一次尝试。 流浪者在测试没有 在这个过程中销毁真正的服务器。方法如下:
用
fab instance1 task1 task2 instance2 task3
3向上奔跑
运行 vagrant ssh config 并将片段复制到您的 ~/.ssh/config , 但将名称改为 VagrantBox ,例如
fab instance1 task1 task2 instance2 task3
4测试ssh vagrantbox是否有效
在fabfile.py中创建一个测试实例
fab instance1 task1 task2 instance2 task3
5使用fab testing install等进行测试。