Skip to main content

Ansible LDIF filter

Ansible filter to read or write LDIF.

Latest version SonarCloud Travis CI License: GPLv3

Install this Ansible Filter:

  • via pip:

pip install ansible-filters-ldif
  • via ansible-galaxy:

ansible-galaxy install 'git+https://github.com/atterdag/ansible-filters-ldif.git'

Ansible filters always runs on localhost.

Examples

Convert dictionary to LDIF

---
- name: Create dictionary with entries
  set_fact:
    dictionary:
      - - dc=example,dc=com
        - dc:
            - example
          description:
            - This is a line longer than 79 characters, so LDIF breaks it up over multiple lines
          o:
            - example.com
          objectClass:
            - dcObject
            - organization
      - - ou=people,dc=example,dc=com
        - objectClass:
            - organizationalUnit
          ou:
            - people
      - - cn=Jane Doe,ou=people,dc=example,dc=com
        - cn:
            - Jane Doe
          mail:
            - jane.doe@example.com
          objectClass:
            - inetOrgPerson
          sn:
            - Doe
      - - cn=John Doe,ou=people,dc=example,dc=com
        - cn:
            - John Doe
          mail:
            - john.doe@example.com
          objectClass:
            - inetOrgPerson
          sn:
            - Doe
      - - ou=groups,dc=example,dc=com
        - objectClass:
            - organizationalUnit
          ou:
            - groups
      - - cn=users,ou=groups,dc=example,dc=com
        - cn:
            - users
          member:
            - cn=Jane Doe,ou=people,dc=example,dc=com
            - cn=John Doe,ou=people,dc=example,dc=com
          objectClass:
            - groupOfNames

- name: "Convert dictionary to LDIF while writing it to /tmp/test.ldif using 'to_ldif' filter"
  copy:
    content: "{{ dictionary | to_ldif }}"
    dest: "/tmp/test.ldif"

Convert LDIF to JSON

---
- name: "Create multi-line string variable with LDIF data"
  set_fact:
    ldif: |
      dn: dc=example,dc=com
      dc: example
      description: This is one line which is longer than
       79 characters, so LDIF breaks it up over multiple lines
      objectClass: dcObject
      objectClass: organization
      o: example.com

      dn: ou=people,dc=example,dc=com
      objectClass: organizationalUnit
      ou: people

      dn: cn=Jane Doe,ou=people,dc=example,dc=com
      objectClass: inetOrgPerson
      cn: Jane Doe
      sn: Doe
      mail: jane.doe@example.com

      dn: cn=John Doe,ou=people,dc=example,dc=com
      objectClass: inetOrgPerson
      cn: John Doe
      sn: Doe
      mail: john.doe@example.com

      dn: ou=groups,dc=example,dc=com
      objectClass: organizationalUnit
      ou: groups

      dn: cn=users,ou=groups,dc=example,dc=com
      objectClass: groupOfNames
      cn: users
      member: cn=Jane Doe,ou=people,dc=example,dc=com
      member: cn=John Doe,ou=people,dc=example,dc=com

- name: "Convert string to JSON while writing it to /tmp/test.json using 'from_ldif' filter"
  copy:
    content: "{{ (ldif | from_ldif) | to_nice_json }}"
    dest: "/tmp/test.json"

Build dependencies

Install the following OS development packages first.

sudo apt-get install libssl-dev libldap2-dev libsasl2-dev python2-dev python3-dev
mkvirtualenv --python=/usr/bin/python3 python3-development
pip install --requirement requirements.txt
gem install travis fry

License

GPLv3.

Metadata

Release files for ansible-filters-ldif 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-filters-ldif 0.0.11
File Size Uploaded
ansible-filters-ldif-0.0.11.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ansible-filters-ldif 0.0.11
File Interpreter ABI Platform
ansible_filters_ldif-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 34.7 kB

Release files / ansible-filters-ldif-0.0.11.tar.gz

Download URL ansible-filters-ldif-0.0.11.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
69eeabef5bd754e926a8ef220c29eff2143476a1053635bca886569ed43e28ef
BLAKE2b-256 checksum
How to use checksums
c6485da9ead126e7395cb43f3f4c21be41192b4b5e7ff993f0fa6af4c7921554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / ansible_filters_ldif-0.0.11-py3-none-any.whl

Download URL ansible_filters_ldif-0.0.11-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef00708a7893e0f933941a65fa3069b387d297ae01135c84e9ed887145c5df59
BLAKE2b-256 checksum
How to use checksums
0f54433641546448c3bb856908a33455dabaf5b529d49955b23071f0cb31af9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

3 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page