这是我的 Ansible 剧本中的一个动作:
- name: Purchase Domain Name
local_action: >
uri
url=https://api.sandbox.namecheap.com/xml.response
method=GET
body="{{ namecheap_purchase_domain_name }}"
status_code=200
HEADER_Content-Type="application/x-www-form-urlencoded"
return_content=yes
register: domain_name_purchase
- debug: var=domain_name_purchase.content
它返回如下内容:
ok: [162.243.67.77] => {
"domain_name_purchase.content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<ApiResponse Status=\"ERROR\" xmlns=\"http://api.namecheap.com/xml.response\">\r\n <Errors>\r\n <Error Number=\"4014104\">Possible duplicate create command for unavailable domain. Try again after 11/20/2013 7:51:07 AM UTC</Error>\r\n </Errors>\r\n <Warnings />\r\n <RequestedCommand>namecheap.domains.create</RequestedCommand>\r\n <CommandResponse Type=\"namecheap.domains.create\">\r\n <DomainCreateResult Domain=\"elitereceipt202321414.com\" ChargedAmount=\"0\" DomainID=\"0\" OrderID=\"0\" TransactionID=\"0\" WhoisguardEnable=\"false\" FreePositiveSSL=\"false\" NonRealTimeDomain=\"false\" />\r\n </CommandResponse>\r\n <Server>WEB1-SANDBOX1</Server>\r\n <GMTTimeDifference>--5:00</GMTTimeDifference>\r\n <ExecutionTime>0.07</ExecutionTime>\r\n</ApiResponse>",
"item": ""
}
是否可以使用类似xmltodict.parse
解析xml并将其转换为字典的东西?特别是我希望返回ApiResponse Status
(返回错误或成功)和Error Number
. 谢谢。