Last active
April 13, 2017 22:59
-
-
Save asifiqbal/a82f8a4e0d665c5bf51804c697cd7a73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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