0
  UserData:
       Fn::Base64: 
          !Sub |
            #!/bin/bash
            echo "Start" >> /var/log/test.txt
            sudo touch /etc/sysconfig/network-scripts/ifcfg-ens6
            sudo echo -e "DEVICE=ens6\nTYPE=Ethernet\nIPADDR=SECONDARY-IP-ADREDD\nNETMASK=255.255.255.xxx\nMTU=9001\nGATEWAY=1xx.7x.2xx.1xx\nIPV6INIT=yes\nIPV6_AUTOCONF=no\nONBOOT=yes\nPEERDNS=no\nNOZEROCONF=yes\nUSERCTL=no\nNM_CONTROLLED=no" >> /etc/sysconfig/network-scripts/ifcfg-ens6
            echo "Stop" >> /var/log/test.txt
-------------

I am passing this userscript in one of my instance using CF and every command works except this two :
           sudo touch /etc/sysconfig/network-scripts/ifcfg-ens6
           sudo echo -e "DEVICE=ens6\nTYPE=Ethernet\nIPADDR=SECONDARY-IP-ADREDD\nNETMASK=255.255.255.xxx\nMTU=9001\nGATEWAY=1xx.7x.2xx.1xx\nIPV6INIT=yes\nIPV6_AUTOCONF=no\nONBOOT=yes\nPEERDNS=no\nNOZEROCONF=yes\nUSERCTL=no\nNM_CONTROLLED=no" >> /etc/sysconfig/network-scripts/ifcfg-ens6

Please let me know what I am doing wrong.

I am getting this no file or directory found for : cat /etc/sysconfig/network-scripts/ifcfg-ens6

OS: Redhat 7

CF File snippet

  • Sadly your question lacks details. You haven't even provided what operating system are you using. – Marcin Mar 08 '22 at 07:54
  • Check the output of `/var/log/cloud-init-output.log` that is where the logs for the user-data scripts are stored. That should tell you which part of your user-data script is failing – WarrenG Mar 08 '22 at 07:54
  • @WarrenG No such log file is getting generated on /var/log/cloud-init-output.log – raushan sharma Mar 08 '22 at 09:47
  • @Marcin what additional details you need. – raushan sharma Mar 08 '22 at 09:48
  • Are there any logs for cloud-init? Seems strange if not. At any rate, it looks like the `/etc/sysconfig/network-scripts` directory doesn't exist. Does it? – theherk Mar 08 '22 at 09:56
  • Yes the directory exists @theherk – raushan sharma Mar 08 '22 at 10:01
  • https://stackoverflow.com/questions/50255413/var-log-cloud-init-output-log-is-not-present-on-rhel-7-5 – raushan sharma Mar 08 '22 at 10:04
  • I guess then you can use the journal to find out why the file commands failed. – theherk Mar 08 '22 at 10:05
  • Instances are getting created using CF and these commands are run using bootup script UserData. @theherk – raushan sharma Mar 08 '22 at 10:08
  • I understand that, but perhaps you will need to modify the script to output filtered contents from the journal, or add requirements to allow you to take a console on the machine and inspect it. – theherk Mar 08 '22 at 10:11
  • I answered before you stated you were using redhat. Redhat doesn't have a cloud-init-output.log. You'll need to grep the `messages` log. Run `sudo grep cloud-init /var/log/messages` – WarrenG Mar 09 '22 at 06:04

1 Answers1

0

When you are running scripts against a container with CloudFormation scripts, you are already the root user for the container. One does not need to use sudo if one is already the root user.

ksinkar
  • 281
  • 2
  • 9