Skip to content

Instantly share code, notes, and snippets.

@asifiqbal
Last active Apr 13, 2017
Embed
What would you like to do?
---
- hosts: localhost
gather_facts: no
roles:
- ldap
vars:
ldap_lookup_config:
url: ldaps://192.168.1.100
base: ou=People,dc=com
binddn: uid=bind,dc=com
bindpw: secret
user_valid:
base: ou=People,dc=com
key: uid
value: cn
filter: (uid={{ term }})
tasks:
- name: Building the ldap context with context header user_valid
set_fact:
members: "{{ members|default([]) + [ { 'context' : 'user_valid' } ] }}"
- name: Stacking the list of uids from UIDS into the ldap context for lookup
set_fact:
members: "{{ members + [ item ] }}"
with_items: "{{ lookup('file', 'uids').splitlines() }}"
- name: Building the full_name dictionary with with uid as key and cn as value
set_fact:
full_name: "{{ full_name|default({}) | combine( { item.uid : item.cn } ) }}"
with_ldap: "{{ members }}"
- name: adding a host
add_host:
hostname: "{{ HOST }}"
- hosts: "{{ HOST }}"
become: yes
gather_facts: no
vars_prompt:
- name: ticket
prompt: "Enter Ticket ID"
private: no
tasks:
- name: Checking if the ticket is an integer value
fail:
msg: "Ticket ID is NOT a valid Number"
when: not ticket|match('[0-9]+$') # ^ is implicit for re.match
- name: Fetching the full_name dict from previous play
set_fact:
full_name: "{{ hostvars['localhost']['full_name'] }}"
- name: Creating account on server with uid and cn and ticket number
loop_control:
loop_var: element
include_role:
name: accounts
vars:
account_users:
- name: "{{ element }}"
comment: "{{ full_name[element] }} - RT {{ ticket }}"
with_items: "{{ lookup('file', UIDFILE).splitlines() }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment