
    Vhx&                         d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
Z
d dlmc mc mc mc mZ d dlmZ d Zd Zedk(  r e        yy)	    )absolute_importdivisionprint_functiona  
module: puppet
short_description: Runs puppet
description:
  - Runs C(puppet) agent or apply in a reliable manner.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  timeout:
    description:
      - How long to wait for C(puppet) to finish.
    type: str
    default: 30m
  puppetmaster:
    description:
      - The hostname of the puppetmaster to contact.
    type: str
  modulepath:
    description:
      - Path to an alternate location for puppet modules.
    type: str
  manifest:
    description:
      - Path to the manifest file to run puppet apply on.
    type: str
  noop:
    description:
      - Override puppet.conf noop mode.
      - When V(true), run Puppet agent with C(--noop) switch set.
      - When V(false), run Puppet agent with C(--no-noop) switch set.
      - When unset (default), use default or puppet.conf value if defined.
    type: bool
  facts:
    description:
      - A dict of values to pass in as persistent external facter facts.
    type: dict
  facter_basename:
    description:
      - Basename of the facter output file.
    type: str
    default: ansible
  environment:
    description:
      - Puppet environment to be used.
    type: str
  confdir:
    description:
      - Path to the directory containing the puppet.conf file.
    type: str
    version_added: 5.1.0
  logdest:
    description:
      - Where the puppet logs should go, if puppet apply is being used.
      - V(all) will go to both C(console) and C(syslog).
      - V(stdout) will be deprecated and replaced by C(console).
    type: str
    choices: [all, stdout, syslog]
    default: stdout
  certname:
    description:
      - The name to use when handling certificates.
    type: str
  tags:
    description:
      - A list of puppet tags to be used.
    type: list
    elements: str
  skip_tags:
    description:
      - A list of puppet tags to be excluded.
    type: list
    elements: str
    version_added: 6.6.0
  execute:
    description:
      - Execute a specific piece of Puppet code.
      - It has no effect with a puppetmaster.
    type: str
  use_srv_records:
    description:
      - Toggles use_srv_records flag.
    type: bool
  summarize:
    description:
      - Whether to print a transaction summary.
    type: bool
    default: false
  waitforlock:
    description:
      - The maximum amount of time C(puppet) should wait for an already running C(puppet) agent to finish before starting.
      - If a number without unit is provided, it is assumed to be a number of seconds. Allowed units are V(m) for minutes
        and V(h) for hours.
    type: str
    version_added: 9.0.0
  verbose:
    description:
      - Print extra information.
    type: bool
    default: false
  debug:
    description:
      - Enable full debugging.
    type: bool
    default: false
  show_diff:
    description:
      - Whether to print file changes details.
    type: bool
    default: false
  environment_lang:
    description:
      - The lang environment to use when running the puppet agent.
      - The default value, V(C), is supported on every system, but can lead to encoding errors if UTF-8 is used in the output.
      - Use V(C.UTF-8) or V(en_US.UTF-8) or similar UTF-8 supporting locales in case of problems. You need to make sure the
        selected locale is supported on the system the puppet agent runs on.
      - Starting with community.general 9.1.0, you can use the value V(auto) and the module will try and determine the best
        parseable locale to use.
    type: str
    default: C
    version_added: 8.6.0
requirements:
  - puppet
author:
  - Monty Taylor (@emonty)
a  
- name: Run puppet agent and fail if anything goes wrong
  community.general.puppet:

- name: Run puppet and timeout in 5 minutes
  community.general.puppet:
    timeout: 5m

- name: Run puppet using a different environment
  community.general.puppet:
    environment: testing

- name: Run puppet using a specific certname
  community.general.puppet:
    certname: agent01.example.com

- name: Run puppet using a specific piece of Puppet code. Has no effect with a puppetmaster
  community.general.puppet:
    execute: include ::mymodule

- name: Run puppet using a specific tags
  community.general.puppet:
    tags:
      - update
      - nginx
    skip_tags:
      - service

- name: Wait 30 seconds for any current puppet runs to finish
  community.general.puppet:
    waitforlock: 30

- name: Wait 5 minutes for any current puppet runs to finish
  community.general.puppet:
    waitforlock: 5m

- name: Run puppet agent in noop mode
  community.general.puppet:
    noop: true

- name: Run a manifest with debug, log to both syslog and console, specify module path
  community.general.puppet:
    modulepath: /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules
    logdest: all
    manifest: /var/lib/example/puppet_step_config.pp
N)AnsibleModulec                 "   t         j                  j                  |       st        j                  |        t         j                  j	                  | dj                  |            }t        j                  t        j                  |t         j                  t         j                  z  t        j                  t        j                  z        d      }|j                  t        j                  |      j!                  d             |j#                          y )Nz{0}.jsonwutf8)ospathexistsmakedirsjoinformatfdopenopenO_CREATO_WRONLYstatS_IRUSRS_IWUSRwritejsondumpsencodeclose)basedirbasenamedata	file_pathout_files        l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/puppet.py_write_structured_datar"      s    77>>'"
GWj&7&7&ABI yy
rzzBKK/LL4<<'	)*-/H NN4::d#**623NN    c                  h   t        t        d9i dt        dd      dt        d      dt        d      dt        d      d	t        d      d
t        d      dt        ddg d      dt        dd      dt        d      dt        dd      dt        d      dt        d      dt        dd      dt        dd      dt        d      dt        dd      dt        d      dt        dd      d t        dd      d!t        d      d"t        dd#      d$g d%&      } | j                  }|d   rDt        j                  j                  |d         s"| j                  d't        |d   (      z  )       |d   st        j                  |        | j                  d   rE| j                  s9t        t        j                         | j                  d   | j                  d          t        j                  |       }|d   s-|d   s(d*} ||      5 }|j                         \  }}}d d d        n1d+} ||      5 }|j                  |d   |d   g,      \  }}}d d d        d-k(  r| j                  |d.       y |d/k(  r#d0v }|rd1}	nd2}	| j                  |||	d$|3       y |d4k(  r| j                  d-d$.       y |d5k(  r#| j                  |d6j                  z  7       y | j                  |d8j                  |fz  7       y # 1 sw Y   xY w# 1 sw Y   xY w):Ntimeoutstr30m)typedefaultpuppetmaster)r(   
modulepathmanifestconfdirnoopboollogdeststdout)allr1   syslog)r(   r)   choices	show_diffFfactsdictfacter_basenameansibleenvironmentcertnametagslist)r(   elements	skip_tagsexecute	summarizewaitforlockdebugverboseuse_srv_recordsenvironment_langCT))r*   r,   )r*   r,   r@   )r*   r+   )argument_specsupports_check_modemutually_exclusivez%Manifest file %(manifest)s not found.)r,   )msgzp_agent_fixed puppetmaster show_diff confdir environment tags skip_tags certname noop use_srv_records waitforlockzu_apply_fixed logdest modulepath environment certname tags skip_tags noop _execute summarize debug verbose waitforlock)_executer   )rcchangedr1   stderr   zadministratively disabledzpuppet is disabledzpuppet did not run)rM   disabledrK   errorr1   rO      |   z%s timed out)rM   rK   r1   rO   z%s failed with return code: %d )r   r7   paramsr
   r   r   	fail_jsonpuppet_utilsensure_agent_enabled
check_moder"   get_facter_dirpuppet_runnerrun	exit_jsoncmd)
moduleprunner
args_orderctxrM   r1   rO   rQ   rK   s
             r!   mainre      s    
eU3
5)
 '
 u%	

 e$
 6"
 eX?Z[
 6
 F#
 !eY?
 %(
 u%
 6E2
 7
  e$!
" 6#
$ %(%
& FE2'
( fe4)
* !f-+
, "uc:-
0 !
5F@ 	A}ww~~a
m,;dz]?, ,  -
 Z=))&1}}Wf&7&7'')MM+,MM'"	$
 ''/FZ=9 H
J 	+3!$B	+ 	+ M
J 	Q3!$1Y<:2O!PB	Q 
QwBfVL	q /&8&C&CH#vf 	 	6 
qAtF6J	s~/v 	 	O 	7377B-G& 	 	*=	+ 	+	Q 	Qs   "L
L(L%(L1__main__)
__future__r   r   r   r(   __metaclass__DOCUMENTATIONEXAMPLESr   r
   r   Aansible_collections.community.general.plugins.module_utils.puppet	communitygeneralpluginsmodule_utilspuppetrX   ansible.module_utils.basicr   r"   re   __name__rU   r#   r!   <module>rs      s[    A @AF-^  	  X X X 4W*t zF r#   