
    Vhg                         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Z d Zd Zd Zd	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
---
module: at
short_description: Schedule the execution of a command or script file via the at command
description:
 - Use this module to schedule a command or script file to run once in the future.
 - All jobs are executed in the 'a' queue.
version_added: "1.0.0"
options:
  command:
    description:
     - A command to be executed in the future.
    type: str
  script_file:
    description:
     - An existing script file to be executed in the future.
    type: str
  count:
    description:
     - The count of units in the future to execute the command or script file.
    type: int
  units:
    description:
     - The type of units in the future to execute the command or script file.
    type: str
    choices: [ minutes, hours, days, weeks ]
  state:
    description:
     - The state dictates if the command or script file should be evaluated as V(present) (added) or V(absent) (deleted).
    type: str
    choices: [ absent, present ]
    default: present
  unique:
    description:
     - If a matching job is present a new job will not be added.
    type: bool
    default: false
requirements:
 - at
author:
- Richard Isaacson (@risaacson)
a  
- name: Schedule a command to execute in 20 minutes as root
  ansible.posix.at:
    command: ls -d / >/dev/null
    count: 20
    units: minutes

- name: Match a command to an existing job and delete the job
  ansible.posix.at:
    command: ls -d / >/dev/null
    state: absent

- name: Schedule a command to execute in 20 minutes making sure it is unique in the queue
  ansible.posix.at:
    command: ls -d / >/dev/null
    count: 20
    units: minutes
    unique: true
N)AnsibleModulec                     |d|d|d|}| j                  |d      \  }}	}
|rt        j                  |       d|d<   y )Nz -f z now +  Tcheck_rcchanged)run_commandosunlink)moduleresultat_cmdcountunitscommandscript_file
at_commandrcouterrs              d/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/posix/plugins/modules/at.pyadd_jobr   Q   sD    +1;uMJ%%j4%@LBS
		+F9    c                     t        | ||      D ]%  }|d|}| j                  |d      \  }}}	d|d<   ' |rt        j                  |        | j                  di | y )Nz -r Tr	   r    )get_matching_jobsr   r   r   	exit_json)
r   r   r   r   r   matching_jobr   r   r   r   s
             r   
delete_jobr"   Y   sm    )&&+F !#)<8
))*t)DC y! 
		+Fvr   c                     g }| j                  dd      }d|z  }| j                  |d      \  }}}|j                         }	t        |	      dk(  r|S t	        |      5 }
|
j                         j                         }d d d        |	D ]j  }|j                         }t        j                         dk7  rdnd}|d	|d	|d   }| j                  |d      \  }}}|v sW|j                  |d          l |S # 1 sw Y   zxY w)
NatqTz%sr	   r   AIXz-cz-lvr   )get_bin_pathr   
splitlineslenopenreadstripsplitplatformsystemappend)r   r   r   matching_jobsatq_cmdatq_commandr   r   r   current_jobs	script_fhscript_file_stringcurrent_jobsplit_current_jobat_optr   s                   r   r   r   c   s   M!!%.G .K%%kD%ALBS>>#L
<A 
k	 6i&^^-3356
 $ 7'--/!*e3#)63DQ3GH
))*t)DC$  !21!567 6 6s   C44C=c                     t        j                  d      \  }}t        j                  |d      }|j	                  | t        j
                  z          |j                          |S )Nat)prefixw)tempfilemkstempr   fdopenwritelinesepclose)r   filedr   filehs       r   create_tempfilerE      sK    !))6E;IIeS!E	KK"**$%	KKMr   c                  *   t        t        t        d      t        d      t        d      t        dg d      t        ddddg      t        d	d
            ddggddggd
      } | j                  dd      }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }|dk(  r|r|s| j	                  d       t        d
|      }|rt        |      }|dk(  rt        | ||||       |rBt        t        | ||            dk7  r)|rt        j                  |        | j                  di | ||d<   ||d<   ||d<   t        | ||||||        | j                  di | y )Nstr)typeint)minuteshoursdaysweeks)rH   choicespresentabsent)rH   defaultrN   boolF)rH   rQ   )r   r   r   r   stateuniquer   r   )argument_specmutually_exclusiverequired_one_ofsupports_check_moder:   Tr   r   rS   rT   z&present state requires count and units)msg)r   rS   r   r   )r   dictr&   params	fail_jsonrE   r"   r(   r   r   r   r    r   )	r   r   r   r   r   r   rS   rT   r   s	            r   mainr]      s   e$%(E"E+PQE9x>STVU3
 '67#]34!F   t,FmmI&G--.KMM'"EMM'"EMM'"E]]8$FU%EFF %g. 6667K@  =>!C		+&F&v&'F=F7OF7OFFFE5';GFvr   __main__)
__future__r   r   r   rH   __metaclass__DOCUMENTATIONEXAMPLESr   r-   r=   ansible.module_utils.basicr   r   r"   r   rE   r]   __name__r   r   r   <module>re      s^    A @)V( 
   4<6r zF r   