Azure ARM template - Multi line bash script

%3CLINGO-SUB%20id%3D%22lingo-sub-2338918%22%20slang%3D%22en-US%22%3EAzure%20ARM%20template%20-%20Multi%20line%20bash%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2338918%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%20Greetings!!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20include%20the%20following%20bash%20scripts%20as%20a%20startup%20script%20for%20a%20VM.%20I%20am%20creating%20the%20VM%20using%20ARM%20template.%20I%20would%20like%20to%20know%20the%20syntax%20to%20use%20to%20include%20this%20multiline%20bash%20script%20in%20ARM%20template.%20If%20it%20is%20one%20line%20script%2C%20it%20is%20working%20fine%20however%20having%20issue%20with%20multi%20line%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Escript%3A%3C%2FP%3E%3CP%3E%3CSPAN%3Eservice%3D%2Fetc%2Fsysconfig%2Fiptables%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ecat%20%26gt%3B%20%24service%20%26lt%3B%26lt%3B%20FW_EOF%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E*filter%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AINPUT%20ACCEPT%20%5B196%3A15477%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AFORWARD%20ACCEPT%20%5B0%3A0%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AOUTPUT%20ACCEPT%20%5B84655%3A113694509%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ECOMMIT%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EFW_EOF%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20have%20included%20it%20as%20follows%20in%20my%20ARM%20template.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Escript%3A%20%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eservice%3D%2Fetc%2Fsysconfig%2Fiptables%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ecat%20%26gt%3B%20%24service%20%26lt%3B%26lt%3B%20FW_EOF%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E*filter%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AINPUT%20ACCEPT%20%5B196%3A15477%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AFORWARD%20ACCEPT%20%5B0%3A0%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3AOUTPUT%20ACCEPT%20%5B84655%3A113694509%5D%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ECOMMIT%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EFW_EOF%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIt%20is%20not%20working.%20Any%20help%20appreciated.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%2C%3CBR%20%2F%3ESantosh%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2356068%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20ARM%20template%20-%20Multi%20line%20bash%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2356068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1049094%22%20target%3D%22_blank%22%3E%40santoshavvari%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20you%20considered%20saving%20that%20script%20in%20e.g.%20GitHub%20and%20referring%20to%20it%20in%20your%20template%2C%20as%20described%20here%3F%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fextensions%2Fcustom-script-linux%23template-deployment%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fextensions%2Fcustom-script-linux%23template-deployment%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlternatively%2C%20you%20could%20leverage%20two%20other%20options%20for%20initial%20VM%20configuration%3A%3C%2FP%3E%3CUL%3E%3CLI%3Ecloud-init%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Flinux%2Fcloud-init-deep-dive%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E%3C%2FLI%3E%3CLI%3Econfig%20management%20tools%20like%20Ansible%2C%20Chef%2C%20etc.%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi,

  Greetings!!!

 

I would like to include the following bash scripts as a startup script for a VM. I am creating the VM using ARM template. I would like to know the syntax to use to include this multiline bash script in ARM template. If it is one line script, it is working fine however having issue with multi line script.

 

script:

service=/etc/sysconfig/iptables

cat > $service << FW_EOF

*filter

:INPUT ACCEPT [196:15477]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [84655:113694509]

COMMIT

FW_EOF

 

I have included it as follows in my ARM template.

 

script: "

service=/etc/sysconfig/iptables

cat > $service << FW_EOF

*filter

:INPUT ACCEPT [196:15477]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [84655:113694509]

COMMIT

FW_EOF"

 

It is not working. Any help appreciated.

 

Thanks,
Santosh

 

1 Reply

@santoshavvari 

 

Have you considered saving that script in e.g. GitHub and referring to it in your template, as described here? https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#template-depl...

 

Alternatively, you could leverage two other options for initial VM configuration:

  • cloud-init - link
  • config management tools like Ansible, Chef, etc.