Zum Hauptinhalt springen
  1. Projekte/

Ansible Module für SOAP Requests

GitHub 💸 ? € ⏱ 2 Monate 📊 intermediate
3 min· loading ·
Inhaltsverzeichnis

Warum
#

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/hufschlaeger/ansible-soap
  • Das Modul soap_request.py in euren library/-Ordner des Playbooks legen oder als Collections-Module einbinden.

Minimalbeispiel
#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
- 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---
- 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).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---
- 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 }}"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
---
- 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: yes ist Standard. Bei selbstsignierten Zertifikaten kann das scheitern – nur zu Testzwecken no setzen.
  • Lange laufende Services mit timeout absichern, damit Playbooks nicht hängen.

Projekt-Info

Status: complete
Version: v1.0