1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CloudStackでインスタンス作成時に自動パス生成スクリプト

Last updated at Posted at 2014-07-31

ユーザー会で使用したスライドにコードが収まらなかったから
Qiitaに上げてたんだけど、やっぱり今見ても放置は酷いですねと思うので手直し。

CloudStack公式ドキュメントにある http://cloudstack.org/dl/cloud-set-guest-password
相変わらずリンク切れ中。やる気を感じます。
cloud-set-guest-password script等でググるとたくさん出てきますので、
そちらをベースにGETして流用していきます。

  • GETしたcloud-set-guest-passwordを編集。

DHCP_FILESの箇所をCentOS7用にするといい感じ。

DHCP_FILES=`find /var/lib/NetworkManager/ -type f -name \*lease` 
  • 実行権限の付与とファイル移動
chmod +x cloud-set-guest-password

mv cloud-set-guest-password /usr/local/bin/
# vim /usr/local/bin/cloud-set-guest-password
cloud-set-guest-password
#!/bin/bash
#
# Init file for Password Download Client
#
# chkconfig: 345 98 02
# description: Password Download Client

# Modify this line to specify the user (default is root)
user=root
# Add your DHCP lease file here
DHCP_FILES=`find /var/lib/NetworkManager/ -type f -name \*lease`

for DHCP_FILE in $DHCP_FILES
do
        if [ -f $DHCP_FILE ]
        then
                DOMR_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
                break;
        fi
done

password=$(wget -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $DOMR_IP:8080)

if [ $? -ne 0 ]
then
        exit 1
fi

password=$(echo $password | tr -d '\r')

if [ -n "$password" ] && [ "$password" != "bad_request" ] && [ "$password" != "saved_password" ]
then
        echo $password | passwd --stdin $user
        if [ $? -gt 0 ]
        then
                usermod -p `mkpasswd $password 42` $user
                if [ $? -gt 0 ]
                then
                        exit 1
                fi
        fi
        wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $DOMR_IP:8080
fi

exit 0
  • systemdにてサーバ起動時のcloud-set-guest-password自動起動化の設定
  1. このコマンドでエラーが出なければOKです。
    systemctl enable cloud-set-guest-password

  2. エラーが出た場合、次のコマンドで状態確認が可能です。
    systemctl status cloud-set-guest-password
    問題がなければ起動の確認が出来ます。
    systemd[1]: Started CloudStack Password Modification Script.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?