�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l Z d d l
m Z d e f d
� � YZ
d e f d � � YZ d � Z e d k r� e � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys�
---
module: ejabberd_user
version_added: "1.5"
author: "Peter Sprygada (@privateip)"
short_description: Manages users for ejabberd servers
requirements:
- ejabberd with mod_admin_extra
description:
- This module provides user management for ejabberd servers
options:
username:
description:
- the name of the user to manage
required: true
host:
description:
- the ejabberd host associated with this username
required: true
password:
description:
- the password to assign to the username
required: false
logging:
description:
- enables or disables the local syslog facility for this module
required: false
default: false
type: bool
state:
description:
- describe the desired state of the user to be managed
required: false
default: 'present'
choices: [ 'present', 'absent' ]
notes:
- Password parameter is required for state == present only
- Passwords must be stored in clear text for this release
- The ejabberd configuration file must include mod_admin_extra as a module.
s5
# Example playbook entries using the ejabberd_user module to manage users state.
- name: create a user if it does not exist
ejabberd_user:
username: test
host: server
password: password
- name: delete a user if it exists
ejabberd_user:
username: test
host: server
state: absent
N( t
AnsibleModulet EjabberdUserExceptionc B` s e Z d Z RS( s. Base exception for EjabberdUser class object ( t __name__t
__module__t __doc__( ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyR M s t EjabberdUserc B` sb e Z d Z d � Z e d � � Z e d � � Z d � Z d � Z d � Z d � Z
d � Z RS( s This object represents a user resource for an ejabberd server. The
object manages user creation and deletion using ejabberdctl. The following
commands are currently supported:
* ejabberdctl register
* ejabberdctl deregister
c C` sv | | _ | j j d � | _ | j j d � | _ | j j d � | _ | j j d � | _ | j j d � | _ d S( Nt loggingt statet hostt usernamet password( t modulet paramst getR R R t usert pwd( t selfR ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt __init__Z s c C` s^ y7 | j | j | j g } | j d | � \ } } } Wn t k
rY d \ } } } n X| S( s� This method will check the current user and see if the password has
changed. It will return True if the user does not match the supplied
credentials and False if it does not
t check_passwordi s required attribute(s) missingN( i Ns required attribute(s) missing( R R R t run_commandR t None( R t optionst rct outt err( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt changedb s
c C` se y1 | j | j g } | j d | � \ } } } Wn t k
rS d \ } } } n Xt t | � � S( s� This method will check to see if the supplied username exists for
host specified. If the user exists True is returned, otherwise False
is returned
t
check_accounti s required attribute(s) missingN( i Ns required attribute(s) missing( R R R R R t boolt int( R R R R R ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt existso s
c C` s: | j r6 t j d | j j � t j t j | � n d S( s? This method will log information to the local syslog facility s
ansible-%sN( R t syslogt openlogR t _namet
LOG_NOTICE( R t entry( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt log| s c C` sY t | � s t � n d | } | d j | � 7} | j d | � | j j | j � � S( sw This method will run the any command specified and return the
returns using the Ansible common module
s ejabberdctl %s t s command: %s( t allR t joinR+ R R t split( R t cmdR ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyR � s
c C` sg y7 | j | j | j g } | j d | � \ } } } Wn t k
rY d \ } } } n X| | | f S( sM The update method will update the credentials for the user provided
t change_passwordi s required attribute(s) missingN( i Ns required attribute(s) missing( R R R R R R ( R R R R R ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt update� s
c C` sg y7 | j | j | j g } | j d | � \ } } } Wn t k
rY d \ } } } n X| | | f S( sa The create method will create a new user on the host with the
password provided
t registeri s required attribute(s) missingN( i Ns required attribute(s) missing( R R R R R R ( R R R R R ( ( sT /usr/lib/python2.7/site-packages/ansible/modules/web_infrastructure/ejabberd_user.pyt create� s
c C` sa y1 | j | j g } | j d | � \ } } } Wn t k
rS d \ } } } n X| | | f S( s>