0
0

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 3 years have passed since last update.

【Rundeck】Rundeckでサーバ再起動を含めたJobを作る(Centos8)

0
Last updated at Posted at 2021-04-29

はじめに

rundeckがマイナーなのもありJobの中で再起動を入れたくても説明してしている記事がない。
ちょくちょく英語記事などは見つかるのだがそれぞれ玄人技だったり断片的だったり使いづらい。
そこで今回はnixy-step-pluginsという公式で作成されている再起動やwaitのstepを追加してくれるプラグインを紹介する。
また、併せて実際に再起動待ちする簡単なJobを作ってみる。

nixy-step-pluginsインストール

GUIからインストールもできるが用途ごとにいくつか別れてしまっているので今回はコマンドラインから行う。

nixy-step-pluginsインストール
yum install git zip
git clone https://github.com/rundeck-plugins/nixy-step-plugins
cd nixy-step-plugins/
./build.sh
mv build/dist/nixy-step-plugins-* /var/lib/rundeck/libext/

ここまでインストール完了、再起動などは必要ない。
Stepを見ると*nixy~が複数追加されていることがわかる。
rundeck-nixy-step.png

これでnixy-step-pluginsで追加されたstepは使えるが、このままだとコマンドが足りないため以下を実行しておく。

ncインストール
yum install nmap-ncat

また、Rundeckを使用する際は何かと捗るのでssh_configに以下の設定をいれておく。

ssh_config
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config

再起動待ちJob作成

わかりやすくする為、今回は再起動前と再起動後のuptimeを比較するだけのJobを作成した。
stepひとつづつ説明しても冗長なので「2」,「3」,「4」だけ個別に解説する。
rundeck-revootJob.png

2.インスタンス再起動

Rundeckはリターンコード0が返ってこないとstepを失敗と判断してしまうため、rebootをバックグラウンドで実行させてexit 0で強制的に0を返させている。
色々やり方は他にもあるが方法の一つとして紹介しておく。
rundeck-reboot2.png

3.waitfor

本来は必要ないが初回ログイン時など以降の処理が速すぎて結構事故るので入れている
設定のIntervalは何秒待つか、Cyclesは何回繰り返すか。
rundeck-reboot3.png

4.再起動完了待機

このstepが実際に再起動待ちをする。
ncコマンドを指定した間隔で打ち、返ってくるようになったら後続のstepに処理を渡す。
hostは変数なのでおそらく固定、portは任意、Intervalは何秒待つか、maxtryは何回までトライするか。
このport-openのstepはローカルとリモートの2種類があり今回のケースではLocalを使用しているので注意。
rundeck-reboot4.png

Job実行結果

再起動後にuptimeがリセットされておりJobのなかでrebootが走っていることが確認できる。
rundeck-jobresult.png

インポート用Job

特になにも考えてないがJobを作ったときは毎回YAMLアップロードしておこうかなと考えている。

再起動待ちJob
- defaultTab: nodes
  description: |-
    <説明>
    再起動前と再起動後にuptimeを取得して起動時間がリセットされていること確認します。
  executionEnabled: true
  id: 0193e0a6-6e76-4398-be48-b241453b23d7
  loglevel: INFO
  name: 再起動待ちJob
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: .*
  nodesSelectedByDefault: true
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: 再起動前
      exec: uptime
    - configuration:
        command: ssh ${node.username}@${node.hostname} 'sudo reboot & exit 0'
      description: インスタンス再起動
      nodeStep: true
      type: localexec
    - configuration:
        cycles: '1'
        interval: '3'
        progress: 'false'
      description: waitfor
      nodeStep: true
      type: nixy-waitfor-sleep-workflow-node-step
    - configuration:
        host: ${node.hostname}
        interval: '10'
        maxtry: '10'
        port: '22'
      description: 再起動完了待機
      nodeStep: true
      type: nixy-waitfor-local-port-open
    - description: 再起動後
      exec: uptime
    keepgoing: false
    strategy: node-first
  uuid: 0193e0a6-6e76-4398-be48-b241453b23d7

あとがき

それぞれが玄人技でなんとかしている中、公式でpluginを作ってくれていたので、本記事で紹介してみた。
nixy-step-pluginsが入っていれば前回紹介した「3.yaceインストール」もインポートできるし実行できる。
ansibleでやればいいじゃんで終わりだけど、目的を実現する手段が増えるのはいいことだと思うので。
(そもそもansibleとrundeckは役割違うのはおいておいて)
なお、今回紹介したのはport-openとsleepだけだけどファイルの存在確認して分岐させたりほかにもいろいろなstepが用意されているのでご興味のある方は触ってみると夢が広がるかもしれません。
あ、私がもっと調べるんですね。はい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?