
    Vh                         d dl mZmZmZ eZdZdZdZd dl	Z		 d dl
Z
dZd dlm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: serverless
short_description: Manages a Serverless Framework project
description:
  - Provides support for managing Serverless Framework (U(https://serverless.com/)) project deployments and stacks.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  state:
    description:
      - Goal state of given stage/project.
    type: str
    choices: [absent, present]
    default: present
  serverless_bin_path:
    description:
      - The path of a serverless framework binary relative to the O(service_path), for example V(node_module/.bin/serverless).
    type: path
  service_path:
    description:
      - The path to the root of the Serverless Service to be operated on.
    type: path
    required: true
  stage:
    description:
      - The name of the serverless framework project stage to deploy to.
      - This uses the serverless framework default "dev".
    type: str
    default: ''
  region:
    description:
      - AWS region to deploy the service to.
      - This parameter defaults to V(us-east-1).
    type: str
    default: ''
  deploy:
    description:
      - Whether or not to deploy artifacts after building them.
      - When this option is V(false) all the functions will be built, but no stack update will be run to send them out.
      - This is mostly useful for generating artifacts to be stored/deployed elsewhere.
    type: bool
    default: true
  force:
    description:
      - Whether or not to force full deployment, equivalent to serverless C(--force) option.
    type: bool
    default: false
  verbose:
    description:
      - Shows all stack events during deployment, and display any Stack Output.
    type: bool
    default: false
notes:
  - Currently, the C(serverless) command must be in the path of the node executing the task. In the future this may be a flag.
requirements:
  - serverless
  - PyYAML
author:
  - Ryan Scott Brown (@ryansb)
aW  
- name: Basic deploy of a service
  community.general.serverless:
    service_path: '{{ project_dir }}'
    state: present

- name: Deploy a project, then pull its resource list back into Ansible
  community.general.serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
  register: sls

# The cloudformation stack is always named the same as the full service, so the
# cloudformation_info module can get a full list of the stack resources, as
# well as stack events and outputs
- cloudformation_info:
    region: us-east-1
    stack_name: '{{ sls.service_name }}'
    stack_resources: true

- name: Deploy a project using a locally installed serverless binary
  community.general.serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
    serverless_bin_path: node_modules/.bin/serverless
a  
service_name:
  type: str
  description: The service name specified in the serverless.yml that was just deployed.
  returned: always
  sample: my-fancy-service-dev
state:
  type: str
  description: Whether the stack for the serverless project is present/absent.
  returned: always
command:
  type: str
  description: Full C(serverless) command run by this module, in case you want to re-run the command outside the module.
  returned: always
  sample: serverless deploy --stage production
NTF)AnsibleModulec           	         | j                   j                  d      }t        j                  j	                  |d      }	 t        |      5 }t        j                  |j                               }|cd d d        S # 1 sw Y   y xY w# t        $ r5}| j                  dj                  |t        |                   Y d }~y d }~ww xY w)Nservice_pathzserverless.ymlz.Could not open serverless.yml in {0}. err: {1}msg)paramsgetospathjoinopenyaml	safe_loadreadIOError	fail_jsonformatstr)moduler   	full_path
sls_configconfiges         p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/serverless.pyread_serverless_configr      s    ==^,DT#34Ii)_ 	
^^JOO$56F	 	 	  iMTTU^`cde`fghhis5   B %A7-	B 7B <B  B 	C+B<<Cc                     t        |       }|j                  d      | j                  d       |rdj                  |d   |      S dj                  |d   |j                  dd            S )Nservicez5Could not read `service` key from serverless.yml filer	   z{0}-{1}stagedev)r   r   r   r   )r   r!   r   s      r   get_service_namer#      sk    #F+Fzz)$TUy 1599F9-vzz'5/IJJ    c                  :   t        t        t        dd      t        ddddg      t        dd	      t        dd	      t        d
d	      t        d      t        d
d	      t        d
d	                  } t        s| j                  d       | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  dd      }| j                  j                  dd      }| j                  j                  dd      }| j                  j                  d      }||dz   }	n| j                  d      dz   }	|dk(  r|	dz  }	n,|dk(  r|	dz  }	n!| j                  dj                  |             |dk(  r|s|	dz  }	n|r|	dz  }	|r|	d j                  |      z  }	|r|	d!j                  |      z  }	|r|	d"z  }	| j                  |	|#      \  }
}}|
d$k7  r[|dk(  r3d%j                  |      |v r | j                  dd|	|t        | |      &       | j                  d'j                  |
||             | j                  dd||	t        | |      (       y ))Nr   T)typerequiredr   presentabsent)r&   defaultchoices )r&   r*   bool)r&   F)r   stateregionr!   deployserverless_bin_pathforceverbose)argument_specz yaml is required for this moduler	   r   r.   r/   r!   r0   r2   r3   r1    
serverlesszdeploy zremove z9State must either be 'present' or 'absent'. Received: {0}z--noDeploy z--force z--region {0} z--stage {0} z
--verbose )cwdr   z-{0}' does not exist)changedr.   commandoutservice_namezNFailure when executing Serverless command. Exited {0}.
stdout: {1}
stderr: {2})r8   r.   r:   r9   r;   )r   dictHAS_YAMLr   r   r   get_bin_pathr   run_command	exit_jsonr#   )r   r   r.   r/   r!   r0   r2   r3   r1   r9   rcr:   errs                r   mainrC      s   6D9E9x>STUB/E2.VT2 $& 1FE2fe4	
F ?@==$$^4LMMg&E]]x(FMMg&E]]x.FMMgu-Emm	51G --++,AB&%+%%l3c9	9	(	9X__`efg	}$Gz!G?))&11>((//<%%g<%@LBS	QwH!7!>!>u!E!LU(G!$3CFE3R  T 	ovvwy{~  AD  E  	F TW"265"A  Cr$   __main__)
__future__r   r   r   r&   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   r   r=   ImportErroransible.module_utils.basicr   r   r#   rC   __name__ r$   r   <module>rN      s    A @@D:
" 
H 5	iK=C@ zF {  Hs   ; AA