Bug 1266627

Summary: Cloud-init reboot fail
Product: Red Hat Enterprise Linux 7 Reporter: Eric Jones <erjones>
Component: cloud-initAssignee: Lars Kellogg-Stedman <lars>
Status: CLOSED NOTABUG QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.1CC: erjones, mfuruta
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-09-29 15:40:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eric Jones 2015-09-25 21:54:02 UTC
Description of problem:
Trying to get system to reboot once cloud init script completes, it does not.

Version-Release number of selected component (if applicable):
Rhel 7.1
cloud init 0.7.6

How reproducible:
very

Steps to Reproduce:
1. Spin up vm with image of rhel 7.1 with flavor m3.large on https://control.os1.phx2.redhat.com/dashboard and add a basic cloud init script, including reboot option, to "Post-completion"
This is the simple cloud init, everything but the power_state works
--------------------------------
#cloud-config      
# vim:syntax=yaml
hostname: example
fqdn: example.example.com
manage_etc_hosts: false
debug: True
ssh_pwauth: True
disable_root: false
chpasswd:
  list: |
    root:redhat
    cloud-user:test
  expire: false
write_files:
  - path: /etc/sysconfig/docker-storage-setup
    permissions: 0644
    owner: root
    content: |
      DEVS=/dev/vdb
      VG=docker-vg
      SETUP_LVM_THIN_POOL=yes
power_state:
  delay: "+1"
  mode: reboot
  message: Bye Bye
  timeout: 10
runcmd:
- echo "MTU=1450" >> /etc/sysconfig/network-scripts/ifcfg-eth0
- service network restart
- echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config
- echo 'UserKnownHostsFile /dev/null' >> /etc/ssh/ssh_config
- sed -i'.orig' -e's/without-password/yes/' /etc/ssh/sshd_config
- service sshd restart
---------------------------
2.log into the instance and run 'tail -f /var/log/cloud-init.log'

Actual results:
Writes the file and allows for ssh into the box, but does not reboot the machine.

Expected results:
Writes the file, allows for ssh into the box, and reboot the machine.

Additional info:
Am I simply using it incorrectly?
Is there a different place to check for debug?
Any kind of help with this, either pointing me to documentation of it in use or fixing the bug, would be great

Comment 2 Lars Kellogg-Stedman 2015-09-28 14:05:21 UTC
Are you use the RHEL guest image?  Or RHEL atomic?  Can you confirm that you've got cloud-init version cloud-init-0.7.6-2.el7.x86_64?

> Is there a different place to check for debug?

Like most services, you can see cloud-init logs with journalctl.  For example:

    journalctl -b | grep -i cloud

Comment 3 Lars Kellogg-Stedman 2015-09-28 14:43:52 UTC
All right, never mind those questions.

The power_state module is not enabled by default in /etc/cloud/cloud.cfg, which means you would need to enable it explicitly.  You have a few options:

1. You can pass a 'cloud_final_modules' configuration section, listing power_state_change *and any other modules you want to run during the final stage*, because this will replace the defaults in /etc/cloud/cloud.cfg.  For example:

    #cloud-config

    disable_root: false
    chpasswd:
      list: |
        root:redhat
      expire: false
    power_state:
      delay: "+1"
      mode: reboot
      message: Bye Bye
      timeout: 10
    cloud_final_modules:
      - rightscale_userdata
      - scripts-per-once
      - scripts-per-boot
      - scripts-per-instance
      - scripts-user
      - ssh-authkey-fingerprints
      - keys-to-console
      - phone-home
      - final-message
      - power_state_change
      
2. You can do it using a `runcmd` shell script instead:
    
    #cloud-config

    disable_root: false
    chpasswd:
      list: |
        root:redhat
      expire: false
    runcmd:
      - sleep 60 && reboot

Comment 4 Eric Jones 2015-09-28 15:14:52 UTC
(In reply to Lars Kellogg-Stedman from comment #3)
> All right, never mind those questions.
> 
> The power_state module is not enabled by default in /etc/cloud/cloud.cfg,
> which means you would need to enable it explicitly.  You have a few options:
> 
> 1. You can pass a 'cloud_final_modules' configuration section, listing
> power_state_change *and any other modules you want to run during the final
> stage*, because this will replace the defaults in /etc/cloud/cloud.cfg.  For
> example:
> 
>     #cloud-config
> 
>     disable_root: false
>     chpasswd:
>       list: |
>         root:redhat
>       expire: false
>     power_state:
>       delay: "+1"
>       mode: reboot
>       message: Bye Bye
>       timeout: 10
>     cloud_final_modules:
>       - rightscale_userdata
>       - scripts-per-once
>       - scripts-per-boot
>       - scripts-per-instance
>       - scripts-user
>       - ssh-authkey-fingerprints
>       - keys-to-console
>       - phone-home
>       - final-message
>       - power_state_change
>       
> 2. You can do it using a `runcmd` shell script instead:
>     
>     #cloud-config
> 
>     disable_root: false
>     chpasswd:
>       list: |
>         root:redhat
>       expire: false
>     runcmd:
>       - sleep 60 && reboot

I will give these a shot.

Thank you.

Comment 5 Eric Jones 2015-09-29 15:40:08 UTC
I failed to try the second one as the first worked immediately. Thank you! I am going to close this now, feel free to change the details as necessary.