܍~c UdZddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZdd lmZd Zd Zd ZejeZdddeddgedededededgedgdZeed<eeZdede de deded df d!Zd"Zd#efd$Zd%Z d&Z!dS)'z"Write Files: write arbitrary filesN)Logger)dedent)log)util)Cloud)Config) MetaSchema get_meta_doc) PER_INSTANCEiFz text/plaincc_write_filesz Write Fileszwrite arbitrary filesa< Write out arbitrary content to files, optionally setting permissions. Parent folders in the path are created if absent. Content can be specified in plain text or binary. Data encoded with either base64 or binary gzip data can be specified and will be decoded before being written. For empty file creation, content can be omitted. .. note:: if multiline data is provided, care should be taken to ensure that it follows yaml formatting standards. to specify binary data, use the yaml option ``!!binary`` .. note:: Do not write files under /tmp during boot because of a race with systemd-tmpfiles-clean that can cause temp files to get cleaned during the early boot process. Use /run/somedir instead to avoid race LP:1707222.alla) # Write out base64 encoded content to /etc/sysconfig/selinux write_files: - encoding: b64 content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4... owner: root:root path: /etc/sysconfig/selinux permissions: '0644' z # Appending content to an existing file write_files: - content: | 15 * * * * root ship_logs path: /etc/crontab append: true a # Provide gziped binary content write_files: - encoding: gzip content: !!binary | H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA= path: /usr/bin/hello permissions: '0755' zt # Create an empty file on the system write_files: - path: /root/CLOUD_INIT_WAS_HERE a  # Defer writing the file until after the package (Nginx) is # installed and its user is created alongside write_files: - path: /etc/nginx/conf.d/example.com.conf content: | server { server_name example.com; listen 80; root /var/www; location / { try_files $uri $uri/ $uri.html =404; } } owner: 'nginx:nginx' permissions: '0640' defer: true write_files)idnametitle descriptiondistrosexamples frequencyactivate_by_schema_keysmetarcfgcloudrargsreturnc|dg}d|D}|s|d|dSt|||jjdS)NrcHg|]}tj|dt| S)defer)rget_cfg_option_bool DEFAULT_DEFER).0fs A/usr/lib/python3/dist-packages/cloudinit/config/cc_write_files.py zhandle..{s= '7MBB zESkipping module named %s, no/empty 'write_files' key in configuration)getdebugrdistro default_owner)rrrrr file_listfiltered_filess r#handler,ws r**IN   ;    nel&@AAAAAr%c|sd}|}|dvrdgS|dvrddgS|dvrdgS|tkrtgS|r!td|ttgS)N)gzgzipapplication/x-gzip)z gz+base64z gzip+base64zgz+b64zgzip+b64application/base64)b64base64z%Unknown encoding type %s, assuming %s)lowerstripTEXT_PLAIN_ENCLOGwarning) encoding_types r#canonicalize_extractionr;s  !''))//11M&&$%%JJJ$&:;; )))$%%&&  3      r%ownerc|sdSt|D]<\}}|d}|s td|dz|=tj|}t|d}t|dd|}tj |d|\}} t|dt} tj |d rd nd } tj||| | tj||| >dS) Npathz3No path provided to write for entry %s in module %sencodingcontentr.r< permissionsappendabwb)omodemode) enumerater&r8r9osr>abspathr;extract_contentsrextract_usergroup decode_perms DEFAULT_PERMSr write_file chownbyname) rfilesr<if_infor> extractionscontentsugpermsrFs r#rrsG  ''%% Fzz&!!  KKEA    wt$$-fjj.D.DEE #FJJy"$=$={KK' 7E(B(BCCAVZZ 66 FF0BBL he%@@@@ q!$$$$!%%r%c||S t|ttfrt|Stt|dS#tt f$rag}||fD]C} |d|z#t$r|d|zY@wxYwtjdg|R|cYSwxYw)Nz%oz%rz0Undecodable permissions %s, returning default %s) isinstanceintfloatstr TypeError ValueErrorrCr8r9)permdefaultrepsrs r#rMrMs | dS%L ) ) %t99 s4yy!$$ $ z " & &A & D1H%%%% & & & D1H%%%%% & FNNNNNs:*AAC(BC"B&#C%B&&C?Cc|}|D]G}|dkrtj|dd} |dkrtj|};|tkr H|S)Nr1F)quietdecoder2)r decomp_gzipr4 b64decoder7)rUextraction_typesresultts r#rKrKsm F  $ $ $%fE%HHHFF & & &%f--FF .  Mr%)"__doc__r4rIloggingrtextwrapr cloudinitrrcloudinit.cloudrcloudinit.configrcloudinit.config.schemar r cloudinit.settingsr rNr r7 getLogger__name__r8r__annotations__r^listr,r;rrMrKr%r#rzsQ)(( $$$$$$!!!!!!######<<<<<<<<++++++  g!!   $6 &w                Q<z -mWWjWWWr ,t  B BB#(B/5B=AB BBBB&2%C%%%%.*     r%