Comments

Xiaohua Guan created an issue. See original summary.

xiaohua guan’s picture

Title: Add user data to ServerTemplate » Launch a instance using a ServerTemplate with user data
xiaohua guan’s picture

If the user data is something like the below, it will fail to launch.

#cloud-config
timezone: 'Asia/Tokyo'
hostname: cloud-orchestrator
preserve_hostname: true
manage_etc_hosts: true
package_update: true
package_upgrade: true
runcmd:
  - [ sed, -i, -e, 's/localhost/localhost cloud-orchestrator cloud-orchestrator/g', /etc/hosts ]
  - [ sh, -c, 'hostname cloud-orchestrator' ]
  - [ sh, -c, 'echo cloud-orchestrator > /etc/hostname' ]
  - [ sh, -c, 'echo "LC_ALL=en_US.UTF-8" >> /etc/environment' ]
  - [ sh, -c, 'echo "LANG=en_US.UTF-8" >> /etc/environment' ]
  - [ apt, update ]
  -
    - sh
    - -c
    - |+
      cat << 'PS' >> /home/ubuntu/.bashrc
      export txt1='\[\033[38;05;75m\]'  # Cyan Dark
      export txt2='\[\033[38;05;122m\]' # Green light
      export txt3='\[\033[38;05;81m\]'  # Cyan
      export txt4='\[\033[01;38m\]'     # White
      export txtrst='\[\033[00m\]'      # Reset
      # Cyan

      PS
  - [ sh, -c, 'echo "PS1=\"\${txt1}[\${txt2}\\\\\$(date +%m/%d) \\\\\$(date +%H:%M)\${txt1}]‌‌‌‌[\${txt3}\\\u\${txt1}@\${txt3}\\\h\${txt1}:\${txt4}\\\w\${txt1}]\${txt4}\\\\$ \${txtrst}\"" >> /home/ubuntu/.bashrc' ]
yas’s picture

@xiaohua-guan

Could you please check a /var/log/cloud-init-output.log file in your launched instance? ... uh, launch itself would fail.. sorry..

xiaohua guan’s picture

StatusFileSize
new1.02 KB
xiaohua guan’s picture

Status: Active » Needs review
xiaohua guan’s picture

@yas

Please review the patch file. Thanks.

yas’s picture

StatusFileSize
new376.54 KB

@xiaohua-guan

Thank you for providing the patch. I found that the launch confirmation page has redundant <br /> in each line in User Data field. If possible, can you remove <br />?

FYI, the following is the screenshot:

screenshot-20190509a.png

yas’s picture

@xiaohua-guan

Use this one for the testing:

#cloud-config
timezone: 'Asia/Tokyo'
hostname: cloud-orchestrator
preserve_hostname: true
manage_etc_hosts: true
package_update: true
package_upgrade: true
runcmd:
  - [ sed, -i, -e, 's/localhost/localhost cloud-orchestrator cloud-orchestrator/g', /etc/hosts ]
  - [ sh, -c, 'hostname cloud-orchestrator' ]
  - [ sh, -c, 'echo cloud-orchestrator > /etc/hostname' ]
  - [ sh, -c, 'echo "LC_ALL=en_US.UTF-8" >> /etc/environment' ]
  - [ sh, -c, 'echo "LANG=en_US.UTF-8" >> /etc/environment' ]
  - [ apt, update ]
  -
    - sh
    - -c
    - |+
      cat << 'PS' >> /home/ubuntu/.bashrc
      export txt1='\[\033[38;05;75m\]'  # Cyan Dark
      export txt2='\[\033[38;05;122m\]' # Green light
      export txt3='\[\033[38;05;81m\]'  # Cyan
      export txt4='\[\033[01;38m\]'     # White
      export txtrst='\[\033[00m\]'      # Reset
      # Cyan

      PS
  - [ sh, -c, 'echo "PS1=\"\${txt1}[\${txt2}\\\$(date +%m/%d) \\\$(date +%H:%M)\${txt1}][\${txt3}\\\u\${txt1}@\${txt3}\\\h\${txt1}:\${txt4}\\\w\${txt1}]\${txt4}\\\$ \${txtrst}\"" >> /home/ubuntu/.bashrc' ]
xiaohua guan’s picture

StatusFileSize
new160.33 KB

@yas

It seems there is nothing wrong in my local browser. Could you confirm the image below?
If I removed the
, the content will be displayed in just one line.

screenshot

xiaohua guan’s picture

yas’s picture

@xiaohua-guan

What I want to expect is that it displays the user-data as it is including the white spaces to keep the indents. In my css, I wanted to apply something like this:

.field--item {
  white-space: pre-wrap;
}

Since User Data field is special, so if you can put <pre>...</pre> in that User Data field in the confirmation screen, that would be great. Is that possible?

xiaohua guan’s picture

StatusFileSize
new3.66 KB
xiaohua guan’s picture

StatusFileSize
new3.66 KB
xiaohua guan’s picture

@yas

Since User Data field is special, so if you can put <pre>...</pre> in that User Data field in the confirmation screen, that would be great. Is that possible?

I added a formatter to deal with it.

Please review the new patch file. Thanks.

yas’s picture

@xiaohua-guan

Thank you for the updated patch. This is sooo fantastic!

@baldwinlouie
@masami

What do you think?

baldwinlouie’s picture

Status: Needs review » Reviewed & tested by the community

@all, this one looks good.

yas’s picture

StatusFileSize
new281.3 KB

@baIdwinlouie

Thank you for your review. Then, I'll merge the patch to 8.x-1.x and 8.x-2.x and close this issue as Fixed.

Here is the screenshot for the comment #15

screenshot-20190510a.png

  • yas committed 7bb06bb on 8.x-1.x authored by Xiaohua Guan
    Issue #3053872 by Xiaohua Guan, yas, baldwinlouie: Launch a instance...

  • yas committed d655a67 on 8.x-2.x authored by Xiaohua Guan
    Issue #3053872 by Xiaohua Guan, yas, baldwinlouie: Launch a instance...
yas’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.