Beruflich muss ich oft eine SOAP-API bedienen, um beispielsweise Testdaten einzupflegen oder Ähnliches. Das sind natürlich repetitive Aufgaben, die automatisiert gehören. Da ich für viele Systeme Ansible benutze, habe ich mich entschieden, ein Ansible-Modul zu schreiben, das diese Aufgaben für mich in Zukunft erledigt.
Hinweis: Dieses Modul kapselt SOAP-Requests so, dass sie sich wie native Ansible-Tasks anfühlen. Ideal für Testdaten-Setup, Stammdatenpflege oder einfache Integrationen.
Features
- 🚿 SOAP-Requests mit minimalem YAML
- ✅ Response-Validierung (Statuscode und Body)
- 🧾 Header-Unterstützung (z. B. Content-Type, Auth)
- 🔁 SOAP 1.1 und 1.2
- 🧭 Namespace- und Prefix-Support
- 🌳 Frei wählbares Body-Root-Tag
- 🧩 Body bequem als Dictionary definierbar
- 🎯 SOAP-Action-Support
- ⏱️ Timeout-Handling
- 🔐 SSL/Cert-Validierung
Voraussetzungen
- Ansible installiert (>= 2.12)
- Python 3.10+
Installation
- Repository klonen:
git clone https://github.com/dhufe/ansible-soap - Das Modul
soap_request.pyin eurenlibrary/-Ordner des Playbooks legen oder als Collections-Module einbinden.
Minimalbeispiel
- hosts: localhost
gather_facts: false
tasks:
- name: Einfacher SOAP-Call
soap_request:
endpoint_url: "https://example.org/service"
body_root_tag: "Ping"
namespace: "https://example.org/ns"
body_dict:
message: "Hello"
register: result
- debug: var=result
Weitere Beispiele
Den kennen bestimmt alle, die mit SOAP arbeiten und erste Tests machen wollten.
---
- name: Test CountryInfoService
hosts: localhost
gather_facts: false
tasks:
- name: "Get Country Name by ISO Code"
soap_request:
endpoint_url: "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
soap_action: ""
body_dict:
sCountryISOCode: "DE"
body_root_tag: "CountryName"
namespace: "http://www.oorsprong.org/websamples.countryinfo"
namespace_prefix: "web"
soap_version: "1.1"
headers:
Content-Type: "text/xml; charset=utf-8"
validate_certs: yes
timeout: 30
register: result
- name: Show CountryInfoService Result
debug:
msg:
- "Status: {{ result.status_code }}"
- "Response: {{ result.body }}"
- "Success: {{ result.success }}"
Der Service konvertiert Zahlen in ausgeschriebene Wörter (also aus 200 wird zweihundert).
---
- name: Test NumberToDollars
hosts: localhost
gather_facts: false
tasks:
- name: "Number to Dollars"
soap_request:
endpoint_url: "https://www.dataaccess.com/webservicesserver/NumberConversion.wso"
soap_action: ""
body_dict:
dNum: "1234.56"
body_root_tag: "NumberToDollars"
namespace: "http://www.dataaccess.com/webservicesserver/"
namespace_prefix: "ns"
soap_version: "1.1"
headers:
Content-Type: "text/xml; charset=utf-8"
validate_certs: yes
timeout: 30
register: result
- name: Show NumberToDollars Result
debug:
msg:
- "Status: {{ result.status_code }}"
- "Response: {{ result.body }}"
- "Success: {{ result.success }}"
---
- name: Test SOAP Module
hosts: localhost
gather_facts: false
tasks:
- name: Test NumberToWords Service
soap_request:
endpoint_url: "https://www.dataaccess.com/webservicesserver/NumberConversion.wso"
soap_action: ""
body_dict:
ubiNum: 500
body_root_tag: "NumberToWords"
namespace: "http://www.dataaccess.com/webservicesserver/"
namespace_prefix: "ns"
soap_version: "1.1"
headers:
Content-Type: "text/xml; charset=utf-8"
validate_certs: yes
register: result
- name: Show NumberToWords Result
debug:
msg:
- "Status: {{ result.status_code }}"
- "Response: {{ result.body }}"
- "Success: {{ result.success }}"
Tipps & Hinweise
- Für viele öffentliche Demoservices ist 1.1 die sichere Wahl.
- Bei 1.2 ändert sich oft der Content-Type (z. B.
application/soap+xml). validate_certs: yesist Standard. Bei selbstsignierten Zertifikaten kann das scheitern – nur zu Testzweckennosetzen.- Lange laufende Services mit
timeoutabsichern, damit Playbooks nicht hängen.