3

Calling all cloud-init and EC2 gurus...

I can't figure this out. I'm using a cloud-init script to bootstrap an EC2 aws-ami instance (through AWS CloudFormation) and when I include the write_files property it changes the command prompt on the instance to -bash-4.2$. If I don't include write_files, I get the regular EC2 shell.

Here is my script so far:

#cloud-config

repo_update: true
repo_upgrade: all

packages:
  - gcc
  - git
  - ruby24
  - ruby24-devel

runcmd:
  - update-alternatives --set ruby /usr/bin/ruby2.4

write_files:
  - path: /home/ec2-user/some-file.yml
    owner: root:root
    permissions: '0644'
    content: |
      <<--SOME-CONTENT-->

final_message: 'The Build Server is ready!'

Anybody know why this is happening or what I might be doing wrong that's making cloud-init change the shell? Or maybe it's a bug/known-issue with cloud-init? This is driving me nuts.

I've already checked the logs /var/log/cloud-init.log and /var/log/cloud-init-output.log and there are no errors or anything to suggest anything went wrong.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

1 Answers1

0

I figured it out, something within cloud-init was not setting the variable $PS1, so the built-in default \s-\v\$ is used.

I fixed it by bootstrapping a modified ~/.bashrc file.

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
parse_git_branch() {
  if ! git rev-parse --git-dir > /dev/null 2>&1; then
    return 0
  fi
  git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
    echo "[$git_branch]"
}
PS1="${debian_chroot:+($debian_chroot)}\[\033[38;5;39m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\[\033[38;5;118m\]\$(parse_git_branch)\[\033[00m\]$ "
halfer
  • 19,824
  • 17
  • 99
  • 186