
    Vh                         d dl mZmZmZ eZdZdZdZ	 d dl	m
Z
 d dlmZ d Zd Zed	k(  r e        y
y
# e$ r eZ
Y #w xY w)    )absolute_importdivisionprint_functiona  
author:
  - Joris Weijters (@molekuul)
module: aix_inittab
short_description: Manages the C(inittab) on AIX
description:
  - Manages the C(inittab) on AIX.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - Name of the C(inittab) entry.
    type: str
    required: true
    aliases: [service]
  runlevel:
    description:
      - Runlevel of the entry.
    type: str
    required: true
  action:
    description:
      - Action what the init has to do with this entry.
    type: str
    choices:
      - boot
      - bootwait
      - hold
      - initdefault
      - 'off'
      - once
      - ondemand
      - powerfail
      - powerwait
      - respawn
      - sysinit
      - wait
  command:
    description:
      - What command has to run.
    type: str
    required: true
  insertafter:
    description:
      - After which inittabline should the new entry inserted.
    type: str
  state:
    description:
      - Whether the entry should be present or absent in the inittab file.
    type: str
    choices: [absent, present]
    default: present
notes:
  - The changes are persistent across reboots.
  - You need root rights to read or adjust the inittab with the C(lsitab), C(chitab), C(mkitab) or C(rmitab) commands.
  - Tested on AIX 7.1.
requirements:
  - itertools
a  
# Add service startmyservice to the inittab, directly after service existingservice.
- name: Add startmyservice to inittab
  community.general.aix_inittab:
    name: startmyservice
    runlevel: 4
    action: once
    command: echo hello
    insertafter: existingservice
    state: present
  become: true

# Change inittab entry startmyservice to runlevel "2" and processaction "wait".
- name: Change startmyservice to inittab
  community.general.aix_inittab:
    name: startmyservice
    runlevel: 2
    action: wait
    command: echo hello
    state: present
  become: true

- name: Remove startmyservice from inittab
  community.general.aix_inittab:
    name: startmyservice
    runlevel: 2
    action: wait
    command: echo hello
    state: absent
  become: true
am  
name:
  description: Name of the adjusted C(inittab) entry.
  returned: always
  type: str
  sample: startmyservice
msg:
  description: Action done with the C(inittab) entry.
  returned: changed
  type: str
  sample: changed inittab entry startmyservice
changed:
  description: Whether the C(inittab) changed or not.
  returned: always
  type: bool
  sample: true
)izip)AnsibleModulec                    ddi}| j                  d      }| j                  || j                  d   g      \  }}}|dk(  rHd}|j                  d      }t	        d |      }t        t        ||            }|j                  dd	i       |S )
NexistFlsitabnamer   )r   runlevelactioncommand:c                 "    | j                         S )N)strip)ss    q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/aix_inittab.py<lambda>z%check_current_entry.<locals>.<lambda>   s    qwwy     T)get_bin_pathrun_commandparamssplitmapdictr   update)module
existsdictr
   rcouterrkeysvaluess           r   check_current_entryr$      s     5!J  *F''v1F(GHNRc	Qw83(&1$tV,-
7D/*r   c                     t        t        t        dddg      t        dd      t        dg d      t        dd      t        d      t        dd	d
d	g            d      } | j                  d   ddd}| j                  d      }| j                  d      }| j                  d      }d}d }t	        |       }| j                  d   d	k(  r| j                  d   dz   | j                  d   z   dz   | j                  d   z   dz   | j                  d   z   }|d   r@| j                  d   |d   k7  s+| j                  d   |d   k7  s| j                  d   |d   k7  rb|d   rN| j
                  s| j                  ||g      \  }}	}|dk7  r| j                  d||       d|d   z   |d<   d|d <   n|d   s	| j                  d!   r3| j
                  sJ| j                  |d"| j                  d!   |g      \  }}	}n#| j
                  s| j                  ||g      \  }}	}|dk7  r| j                  d#||       d$| j                  d   z   |d<   d|d <   np| j                  d   d
k(  r^|d   rY| j
                  s=| j                  || j                  d   g      \  }}	}|dk7  r| j                  d%||       d&|d   z   |d<   d|d <    | j                  d'i | y )(NstrTservice)typerequiredaliases)r(   r)   )bootbootwaitholdinitdefaultoffonceondemand	powerfail	powerwaitrespawnsysinitwait)r(   choices)r(   presentabsent)r(   defaultr7   )r   r   r   r   insertafterstate)argument_specsupports_check_moder   F )r   changedmsgmkitabrmitabchitabr   r<   r   r   r   r   r	   zcould not change inittab)rA   r   r!   zchanged inittab entry rA   r@   r;   z-izcould not adjust inittabzadd inittab entry z$could not remove entry from inittab)zremoved inittab entry  )	r   r   r   r   r$   
check_moder   	fail_json	exit_json)
r   resultrB   rC   rD   r   r!   current_entry	new_entryr    s
             r   mainrL      s:   54)Eut4U -  ed3%(E9x>ST'
* !-F4 f%F   *F  *F  *F	
B
C (/M }}W* MM&)C/&--
2KK--)*,/028--	2JK	
 g&j)]:-FFh'=+BBi(M),DD W%((%+%7%78K%LNRc7$$623 % H =f@U Uu$(y! #7+==/!,,)/););#T6==+GS*US# ",,)/););#Y/*1S# 7$$)CPS$T 9FMM&<Q Qu$(y!	w	8	+!$$!'!3!3V]]623"5S#7$$Brs % T9M&<QQF5M $F9Fvr   __main__N)
__future__r   r   r   r(   __metaclass__DOCUMENTATIONEXAMPLESRETURN	itertoolsr   ImportErrorzipansible.module_utils.basicr   r$   rL   __name__rE   r   r   <module>rX      so    A @@D@
& 5 _D zF w  Ds   4 >>