Skip to main content

Ansible Api Warpper

Project description

说明

这是一个Ansible Python Api的封装。

安装

$ python setup.py install

简单使用

from Asi import Api


if __name__ == "__main__":
	hosts = [
		{
			"hostname": "localhost",
			"port": 22,
			"vars": {
				"ansible_ssh_user": "root",
				"ansible_ssh_pass": "p@ssw0rd"
			}
		},
		{
			"hostname": "192.168.152.142",
			"port": 22,
			"vars": {
				"ansible_ssh_user": "root",
				"ansible_ssh_pass": "p@ssw0rd"
			}
		}
	]

	Api().module("shell", args="ls", register='shell_out', task_name="test")\
		 .module("debug", args={"msg":"{{shell_out.stdout}}"})\
		 .run(hosts)	

获取返回数据

run方法前面调用json方法,并且run方法中callback参数需为None,如果自己实现callback, 则需要在callback增添属性results

from Asi import Api
import json


if __name__ == "__main__":
	hosts = [
		dict(hostname="127.0.0.1", port=22)
	]

	api = Api()
	api = api.module("shell", args="ls", register="shell_out")
	api = api.module("debug", args=dict(msg="{{shell_out}}"))
	api = api.json()
	print("result")
	print(json.dumps(api.run(hosts), indent=4))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Asi-1.2.1.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file Asi-1.2.1.tar.gz.

File metadata

  • Download URL: Asi-1.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.5

File hashes

Hashes for Asi-1.2.1.tar.gz
Algorithm Hash digest
SHA256 763853c6ca9d1739b66ce42cab0394930a74c278b6431c2686e4dec9191e0c30
MD5 8d9d03e5c164a86781af66a5da3839ee
BLAKE2b-256 225fbf6183f9895f8a2a1f7d9ad40fac1a48f484f85342443431e88aa0e4e7a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page