
    Vh]"                         d dl mZmZmZ eZdZdZd dlZd dl	m
Z
mZ d dlmZ dZ	 d dlZdZd	 Zd
 Zedk(  r e        yy# e$ r dZY w xY w)    )absolute_importdivisionprint_functiona  
module: nomad_job
author: FERREIRA Christophe (@chris93111)
version_added: "1.3.0"
short_description: Launch a Nomad Job
description:
  - Launch a Nomad job.
  - Stop a Nomad job.
  - Force start a Nomad job.
requirements:
  - python-nomad
extends_documentation_fragment:
  - community.general.nomad
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - Name of job for delete, stop and start job without source.
      - Name of job for delete, stop and start job without source.
      - Either this or O(content) must be specified.
    type: str
  state:
    description:
      - Deploy or remove job.
    choices: ["present", "absent"]
    required: true
    type: str
  force_start:
    description:
      - Force job to started.
    type: bool
    default: false
  content:
    description:
      - Content of Nomad job.
      - Either this or O(name) must be specified.
    type: str
  content_format:
    description:
      - Type of content of Nomad job.
    choices: ["hcl", "json"]
    default: hcl
    type: str
seealso:
  - name: Nomad jobs documentation
    description: Complete documentation for Nomad API jobs.
    link: https://www.nomadproject.io/api-docs/jobs/
at  
- name: Create job
  community.general.nomad_job:
    host: localhost
    state: present
    content: "{{ lookup('ansible.builtin.file', 'job.hcl') }}"
    timeout: 120

- name: Connect with port to create job
  community.general.nomad_job:
    host: localhost
    port: 4645
    state: present
    content: "{{ lookup('ansible.builtin.file', 'job.hcl') }}"
    timeout: 120

- name: Stop job
  community.general.nomad_job:
    host: localhost
    state: absent
    name: api

- name: Force job to start
  community.general.nomad_job:
    host: localhost
    state: present
    name: api
    timeout: 120
    force_start: true
N)AnsibleModulemissing_required_lib)	to_nativeTFc                     t        t        t        dd      t        dd      t        dddg	      t        d
d      t        dd      t        d
d      t        d      t        d      t        d      t        d      t        ddgd      t        d      t        d
d      t        dd            dddggddgg      } t        s| j                  t	        d             | j
                  j                  d      | j
                  j                  d      f}t        j                  | j
                  j                  d      | j
                  j                  d      | j
                  j                  d      | j
                  j                  d      | j
                  j                  d      || j
                  j                  d       | j
                  j                  d!      "      }| j
                  j                  d#      dk(  rX| j
                  j                  d      r-| j
                  j                  d$      s| j                  d%       d}| j
                  j                  d      r| j
                  j                  d&      dk(  r| j
                  j                  d      }	 t        j                  |      }t               }||d'<   	 |j                  d(      }|| j                  d)       |j                  j                  ||d*      }|d+   j                  d,      d-k(  s-d}| j                  s|j                   j#                  |      }	n|}	n|}	| j
                  j                  d&      dk(  r	 | j
                  j                  d      }
|j                   j'                  |
      }t               }||d'<   	 j                  d(      }|j                  j                  |d*      }|d+   j                  d,      d-k(  s-d}| j                  s|j                   j#                  |      }	n|}	n|}	| j
                  j                  d$      r	 t               }| j
                  j                  d      r| j
                  j                  d      }nd/   }|j                  j7                  |      }|d0   d1k(  r|}	nd1|d0<   d|d2<   ||d'<   | j                  s|j                   j#                  |      }	nn|j8                  j;                  |      }	|	j<                  d3k(  s%| j                  t        |	j4                               t        j                  |	j4                        }	d}| j
                  j                  d#      dk(  r!	 | j
                  j                  d      | j
                  j                  d      }n| j
                  j                  d&      dk(  r9|j                   j'                  | j
                  j                  d            }|d/   }| j
                  j                  d&      dk(  r | j
                  j                  d      }|d/   }|j                  j7                        }|d0   d4k(  rd}|}	n,| j                  s|j                  j?                  |      }	n|}	d}| jA                  	5       y # t        $ r&}| j                  t        |             Y d }~!d }~ww xY w# t$        $ r&}| j                  t        |             Y d }~d }~ww xY w# t        j(                  j*                  j,                  $ rh}t/        |j0                  j2                        d.z   t/        |j0                  j4                        z   }| j                  t        |             Y d }~d }~ww xY w# t$        $ r&}| j                  t        |             Y d }~d }~ww xY w# t$        $ r&}| j                  t        |             Y d }~d }~ww xY w# t$        $ r&}| j                  t        |             Y d }~d }~ww xY w)6NTstr)requiredtypeinti&  )r   defaultpresentabsent)r   choicesbool   path)r   hcljson)r   r   F)r   no_log)hostportstateuse_ssltimeoutvalidate_certsclient_cert
client_key	namespacenamecontent_formatcontentforce_starttokenr!   r#   )argument_specsupports_check_modemutually_exclusiverequired_one_ofzpython-nomad)msgr   r   r   r   r   r   r   r    r%   )r   r   securer   verifycertr    r%   r   r$   z.For start job with name, force_start is neededr"   jobIDz Cannot retrieve job with ID None)diffDiffTypeNone NameStatusrunningStop   dead)changedresult)!r   dictimport_nomad	fail_jsonr   paramsgetnomadNomadr   loads
ValueErrorr   r.   plan_job
check_modejobsregister_job	Exceptionparseapi
exceptionsBadRequestNomadExceptionr
   
nomad_respreasontextget_jobvalidatevalidate_jobstatus_codederegister_job	exit_json)modulecertificate_sslnomad_clientr;   job_jsoner.   job_idplanr<   job_hclerrr*   job_names                 o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/nomad_job.pyrunrc   m   s   t%05$/y(.CDfd3eQ/VT:&)(&5!Ge$&%8E$/
  !Y
 Y
+F4 1.AB}}((79J9J<9XYO;;]]v&]]v&}}  +!!),}}  !12--##K0mm(	L }}!Y.==V$V]]->->}-M!QR==Y'}}  !12f<!==,,Y77#zz(3H f%E
7%\\$/F~((-O(P'++44VSt4LD<++F3v="&%00%1%6%6%C%CC%HF%)F!% }}  !12e;9$mm//	:G+0066w?H&C!)CJ7%\\$/F'++44VSt4LD<++F3v="&%00%1%6%6%C%CC%HF%)F!% ==]+3f==$$V,%}}008H'/H'++33H=H%2%F)2HX&',HV$!)CJ!,,!-!2!2!?!?!D!-!6!6!C!CC!H%11S8",,6;;1G,H!%FKK!8"G }}!X-	/==$$V,4!==,,V4==$$%56%?+0066v}}7H7H7STH'/H==$$%56&@%}}00;H'/H""**84C8}&(()--<<XFF F WV4 " 7$$1$667" ! 7$$1$667 yy++DD 9cnn334s:SATAT=UUC$$3$889 ! 7$$1$6674  3  Yq\ 2232  	/1..	/s   (Z4 B	[& 5A\ ;A5^* D_  D ` 4	[#=[[#&	\/\\'^'?A^""^'*	_3__	`%``	`=`88`=c                      t                y )N)rc        rb   mainrg     s    Erf   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESr   ansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   r>   rB   ImportErrorrc   rg   __name__re   rf   rb   <module>rq      sv    A @4l>  J AL
W5t

 zF G  Ls   A   A
	A
