
    Vh                     r    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
---
module: rabbitmq_plugin
short_description: Manage RabbitMQ plugins
description:
  - This module can be used to enable or disable RabbitMQ plugins.
author:
  - Chris Hoffman (@chrishoffman)
options:
  names:
    description:
      - Comma-separated list of plugin names. Also, accepts plugin name.
    type: str
    required: true
    aliases: [name]
  new_only:
    description:
      - Only enable missing plugins.
      - Does not disable plugins that are not in the names list.
    type: bool
    default: false
  state:
    description:
      - Specify if plugins are to be enabled or disabled.
    type: str
    default: enabled
    choices: [enabled, disabled]
  broker_state:
    description:
      - Specify whether the broker should be online or offline for the plugin change.
    type: str
    default: online
    choices: [online, offline]
  prefix:
    description:
      - Specify a custom install prefix to a Rabbit.
    type: str
aj  
- name: Enables the rabbitmq_management plugin
  community.rabbitmq.rabbitmq_plugin:
    names: rabbitmq_management
    state: enabled

- name: Enable multiple rabbitmq plugins
  community.rabbitmq.rabbitmq_plugin:
    names: rabbitmq_management,rabbitmq_management_visualiser
    state: enabled

- name: Disable plugin
  community.rabbitmq.rabbitmq_plugin:
    names: rabbitmq_management
    state: disabled

- name: Enable every plugin in list with existing plugins
  community.rabbitmq.rabbitmq_plugin:
    names: rabbitmq_management,rabbitmq_management_visualiser,rabbitmq_shovel,rabbitmq_shovel_management
    state: enabled
    new_only: true

- name: Enables the rabbitmq_peer_discovery_aws plugin without requiring a broker connection.
  community.rabbitmq.rabbitmq_plugin:
    names: rabbitmq_peer_discovery_aws_plugin
    state: enabled
    broker_state: offline
a  
enabled:
  description: list of plugins enabled during task run
  returned: always
  type: list
  sample: ["rabbitmq_management"]
disabled:
  description: list of plugins disabled during task run
  returned: always
  type: list
  sample: ["rabbitmq_management"]
N)AnsibleModulec                   ,    e Zd Zd ZddZd Zd Zd Zy)RabbitMqPluginsc                    || _         d}|j                  d   r8t        j                  j	                  t        j                  j                  |j                  d   d            r.t        j                  j                  |j                  d   d      }nt        j                  j	                  t        j                  j                  |j                  d   d            r.t        j                  j                  |j                  d   d      }n"|j                  d|j                  d   z         t        j                  j                  |d      | _        y |j                  dd      | _        y )	N prefixbinsbinzNo binary folder in prefix %s)msgzrabbitmq-pluginsT)	moduleparamsospathisdirjoin	fail_json_rabbitmq_pluginsget_bin_path)selfr   bin_paths      v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/rabbitmq/plugins/modules/rabbitmq_plugin.py__init__zRabbitMqPlugins.__init__b   s    =="ww}}RWW\\&--*A5IJ77<<h(?Grww||FMM(,CVLM77<<h(?H   %Dv}}U]G^%^ _%'WW\\(<N%OD"%+%8%89KT%RD"    c                     | j                   j                  r| j                   j                  rC|rA| j                  g}| j                   j                  ||z   d      \  }}}|j	                         S t               S )NT)check_rc)r   
check_moder   run_command
splitlineslist)r   argsforce_exec_in_check_modecmdrcouterrs          r   _execzRabbitMqPlugins._execr   sc    {{%%$++*@*@E]))*C;;223:2MLBS>>##vr   c                 l    | j                  g dd      }g }|D ]  }|s |S |j                  |        |S )N)r"   z-Ez-mT)r)   append)r   list_outputpluginsplugins       r   get_allzRabbitMqPlugins.get_ally   sI    jj!5t<! 	#F  NN6"	#
 r   c                 `    | j                  dd| j                  j                  d   z  |g       y )Nenable--%sbroker_stater)   r   r   r   names     r   r1   zRabbitMqPlugins.enable   s)    

Hft{{'9'9.'II4PQr   c                 `    | j                  dd| j                  j                  d   z  |g       y )Ndisabler2   r3   r4   r5   s     r   r8   zRabbitMqPlugins.disable   s)    

Iv(:(:>(JJDQRr   N)F)__name__
__module____qualname__r   r)   r/   r1   r8    r   r   r   r   `   s    S RSr   r   c            
      (   t        t        ddg      t        dd      t        dddg	      t        d
d
dg	      t        dd             } t        | d      }t               }|j                  d   j                  d      }|j                  d   }|j                  d   }t	        |      }|j                         }g }g }	|dk(  rd|s3|D ].  }
d|
v r|
|vs|j                  |
       |	j                  |
       0 |D ])  }||vs|j                  |       |j                  |       + n.|D ])  }
|
|v s|j                  |
       |	j                  |
       + t        |      dkD  xs t        |	      dkD  |d<   ||d<   |	|d<    |j                  di | y )NTr6   )requiredaliasesnobool)defaulttypeenableddisabled)rB   choicesonlineofflineF)r>   rB   )namesnew_onlystater3   r   )argument_specsupports_check_moderI   ,rJ   rK    r   changedr<   )dictr   r   splitr   r/   r8   r+   r1   len	exit_json)arg_specr   resultrI   rJ   rK   rabbitmq_pluginsenabled_pluginsrD   rE   r.   r6   s               r   mainrY      s   D6(3d09y*.EF(Xy4IJUD1H  F
 VFMM'"((-E}}Z(HMM'"E&v.&..0OGH	) ,&=&$,,V4OOF+,  	%D?* ''-t$	%
 & 	(F ((0'	(
 Gq(=CMA,=F9F9!F:Fvr   __main__)
__future__r   r   r   rC   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   objectr   rY   r9   r<   r   r   <module>rb      sZ    A @%N:
 
 4'Sf 'ST-` zF r   