使用python调用playbook和shell脚本
我的python脚本为:
#!/usr/bin/env python import ansible.playbook from ansible import callbacks from ansible import utils import json import commands status, result = commands.getstatusoutput('sh /home/prod/svnrepos/test/install.sh') print status, result example_host = ansible.inventory.host.Host( name = '10.204.186.92', port = 22, ) example_group = ansible.inventory.group.Group( name = 'sample_group_name' ) example_group.add_host(example_host) example_inventory = ansible.inventory.Inventory() example_inventory.add_group(example_group) stats = callbacks.AggregateStats() playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY) runner_cb = callbacks.PlaybookRunnerCallbacks(stats,verbose=utils.VERBOSITY) res=ansible.playbook.PlayBook( playbook = 'playbook.yml', stats = stats, callbacks = playbook_cb, runner_callbacks = runner_cb, inventory = example_inventory, subset = 'sample_group_name' ).run() print json.dumps(res, sort_keys=True, indent=4, separators=(',', ': '))
playbook为:
shell脚本为:
执行python脚本,结果为:
加密之后向加密磁盘copy文件修改文件属性
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-19 22:43:34