LoginSignup
1
1

More than 5 years have passed since last update.

Amazon-linuxでログインメッセージを表示させる

Last updated at Posted at 2017-04-07

目的

sshした際、ホスト名を出力させることで、オペレーションミスを防ぐ

方法

設定ファイルを作って、itamaeでプロビジョニングする

前提

IAMでdescribe-instancesが実行できる

設定

itamae構成

cookbooks/motd/
├── set-motd.rb
└── file
    └── etc
        └── update-motd.d
            └── 99-server-name

3 directories, 2 files
set-motd.rb
remote_file "/etc/update-motd.d/99-server-name" do
  source "file/etc/update-motd.d/99-server-name"
  owner "root"
  group "root"
  mode "755"
end

execute "apply motd" do
  command "sudo update-motd"
end
99-server-name
#!/bin/bash

region=$(curl -s  http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/.$//')
myInstanceId=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
tagName=$(aws ec2 describe-instances --region ${region} --query "Reservations[].Instances[?InstanceId==\`${myInstanceId}\`].[Tags[?Key==\`Name\`].Value]" --output text)

cat << EOF

*****************************************
_________________________________________
< This Server is ${tagName} >
-----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\n
                ||----w |
                ||     ||
*****************************************

EOF
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