ページ

2015年2月28日土曜日

Ansibleで設定ファイルの行を書き換える

すでにある環境に対して、Ansibleで構成変更するとき、lineinfile で行を置き換えるのではなく、既存の行の一部を変更したいことがある。
しかし、このようなときに、冪等性を確保するのは意外に難しい。正規表現では、最小一致や否定先読みアサーションを使ったとしても、うまく行を選択できないか、あるいは複数回実行すると、そのたびに変更されてしまったりする。
とりあえず、grepで書き換えるべきかどうかを判定して、必要なときだけ書き換えるようにしてみた。
- hosts: servers
  vars:
    httpd_conf: /etc/apache2/apache2.conf
  tasks:
    - name: grep %{Session}C
      command: grep '^LogFormat[[:space:]].*%{Session}C.*[[:space:]]combined' {{httpd_conf}}
      register: grep
      ignore_errors: True
      failed_when: False
      changed_when: False
    - name: change httpd.conf
      lineinfile:
        backup=yes
        backrefs=yes
        dest={{httpd_conf}}
        state=present
        regexp="^(LogFormat\s+\")(.*)(\"\s+combined)$"
        line="\1\2 \\\\\"%{Session}C\\\\\" \3"
      when: grep.rc == 1

2015年2月26日木曜日

マルチテラバイトな時代にソフトウェアRAIDはつらいよね

QNAP NAS のディスクを一回り大きい容量のものに交換したんだけど、マルチテラバイトな時代にソフトウェアRAIDはつらいよね、ということを実感した。

1本目交換、mdadm の recovery が走る。1日かかる。
2本目交換、mdadm の recovery が走る。1日かかる。

ボリュームサイズを拡張する。
拡張エラーが発生。md0 の resize2fs ができていない。
resize2fs を手動で実行する。

ボリュームサイズは拡張できたが、ボリュームがすこし小さい。
RAIDボリュームのスーパーブロックの形式が version-0.90 なので  4TB の壁があるらしい。
手動で md0 を --metadata=1.0 で再構成することにした。

/etc/init.d/services.sh stop しても止まらないものがあることに気がつく。
Optware の sshd の起動スクリプトのできが悪くて、stop でも start でも sshd を止めて起動し直すだけになっているからだ。拡張エラーが発生したのは、もしかしてこいつのせいか。

データのロストなしで再構成できたんだけど、一度ミラーの片側を解除したのが気に入らなかったのか、読み込み/書き込みエラー、というのが出ている。
とりあえず、リビルドが完了したら再起動してみる。
リビルドが完了まで2日かかる。

リビルドが完了したので再起動してみる。やはり読み込み/書き込みエラーのまま。
しかも、エラーを検出しているため、起動時にミラーの片側を切り離しているじゃありませんか。

エラーが出ている側のディスクのパーティションを削除して、先頭から dd if=/dev/zero で書きつぶす。
途中でステータスを見るとエラーが消えているので、dd を止めて再起動してみたところ、ちゃんとリビルドがかかっている。
どうやらこで大丈夫そう。リビルドが完了まで2日待つ。

リビルドが完了した。めでたしめでたし。
ここまで丸々一週間以上かかった。

2015年2月9日月曜日

Rundeck コマンド実行のされ方を見る

Rundeskではどのような形でコマンドが実行されるのかを見ていきます。

Command メニューから、対象を指定して、アドホックなコマンド実行ができます。

localhost を対象に uname -a を実行してみます。


実行結果が表示されます。


このコマンドがどのような形で実行されているのを確かめるために、pstree -p --show-parents $$ を実行してみます。
pstree の親プロセスはshで、さらにその親プロセスがjavaです。つまり、Rundeckのサービスを実行しているjavaプロセスから、直接コマンドが実行されています。localhostのときはsshを使わないのですね。
ノードにubuntu-hostというリモートホストを登録したので、このノードを対象に再びpstreeを実行してみます。

こんどは、親プロセスがsshdになっています。ssh経由で実行したようです。

Rundeckでは対象がlocalhostのときは、コマンドを直接実行し、それ以外のリモートホストではssh経由で実行していることがわかりました。
どうやらlocalhostを特別扱いしているようです。

対象ノードがlocalhostの場合には、コマンドの実行も少し変わるようで、コマンドリストを指定したときに、期待した実行結果になりません。

この図は実行コマンドとして、
LANG=ja_JP.UTF-8; export LANG; printenv LANG; date
を実行した時のものですが、localhostの実行では日付の出力にロケール設定が効いていません。

ならばと、コマンドに
sh -c 'LANG=ja_JP.UTF-8; export LANG; printenv LANG; date'
指定したときは、さらに不思議な結果になります。
Commandでコマンドリストを使うときはかなり注意が必要なようです。




Rundesk ジョブの作成と実行

ジョブの作成

Jobs 画面を開いて、「Create Job」から「+New Job…」を選択します。


Create New Job の画面になります。


Job Name pstree

Workflow では、Add a Step で Command を選択します。
Command として pstree -p --show-parents $$ を指定します。

Nodes では、それぞれのノードにコマンドを発行するため Dispatch to Nodes を選択します。

Node Filter に .* を入力し、Set Filter をクリックします。

ほかの項目はデフォルトにままでかまいません。

これで Create をクリックしてジョブを作成します。


ジョブの実行

作成したジョブを実行します。
ジョブの一覧から先ほど作成したpstreeを選択します。
psteeジョブの画面に切り替わります。

Run Job Now をクリックします。

ジョブが実行される様子が表示されます。
今回のジョブはステップが一つしかないのですぐに終了するでしょう。

実行結果が表示されます。

Summary

実行結果の要約です。

Report

ジョブの実行結果をノードやステップごとに確認できます。


Log Output

ジョブの出力が確認できます。

Definition

ジョブを実行したときのワークフローの定義が表示されます。

ジョブの実行対象ノード

Nodes の Change the Target Nodes にチェックを入れると、実行対象のノードを限定することができます。

ノード localhost だけを選んで実行してみます。

Summary画面ではわかりにくいですが、よく見ると Complete 100% 1/1 と、対象1ノードで、成功1ノードになっています。

ジョブの詳細設定

実行対象

ジョブを発行する対象は
  • Nodes のところで Dispatch to Nodes (各ノードに対しSSH経由で実行),
  • Execute locally (Rundeckサーバ上で実行)
から選択します。

Dispatch to Nodes を選択したときは、Node Filter で実行対象のノードを選択します。このときの指定には次のような方法があります。Node Filter の「?」をクリックすればヘルプが表示されます。

Select nodes by name: 名前を列挙する
mynode1 mynode2
This will select both nodes.
Filter nodes by attribute value: 属性値で選択する
  • Include: attribute: value
  • Exclude: !attribute: value
Use Regular Expressions: 正規表現で選択することができる
hostname: dev(\d+).test.com.
Regex syntax checking:
attribute: /regex/
attribute: /regex/
Examples:
All nodes すべてのノード
name: .*
Nodes tagged "production" 「production」というタグがついたノード
tags: production
Unix nodes  OSがunix」のノード
osFamily: unix

実行コマンド

実行するコマンド列はWorkflowとして設定します。

ステップには2種類のタイプがあります。
  • Node Steps : 各ノードごとに実行する
  • Workflow Steps : ノードに関係なく1度だけ実行する
各Node Steps は、以下の中から選択します。Workflow Steps のときに選択できるのはJob Reference のみです。
 Command - Execute a remote command
 Script - Execute an inline script
 Script file or URL - Execute a local script file or a script from a URL
 Job Reference - Execute another Job for each Node
2 Node Step Plugins
 Copy File - Copy a file to a destination on a remote node.
 Local Command - Run a command locally on the server
error hander で、ステップがエラー終了したとき、ワークフローを打ち切るか、実行を続けるかを指定できます。また、エラー処理のためのコマンドを実行することもできます。

コマンド実行

Commandで指定したコマンドは ssh node 'コマンド' のように実行されます。コマンドはリモートホスト上でシェルが評価して実行されます。

一方、Local Commandでは、コマンドは空白で分割されたのち、直接 exec(3) で実行されます。このときシェルは介在しないため、単純コマンドしか実行できません。パラメータ置換やパイプライン、コマンドリストなどが必要であれば、sh -c 'コマンド' のように指定してください。

引数

Optionsでジョブの引数を宣言することができます。
引数が取り得る値は、Allowed Valuesで指定します。GUIからジョブを実行するときに、この値を選択することができます。

引数はステップでは次のようにして参照できます。
The option values will be available to scripts in these forms:
Bash: $RD_OPTION_NAME (ローカル実行のみ。環境変数として渡されます。)
Commandline Arguments: ${option.name}
Script Content: @option.name@

Node Filter で name:${option.nameのようにして使うこともできます。

ジョブの名前

ジョブの名前は任意に指定できます。後から変更することもできます。
ただしJob Referenceで参照しているジョブの名前を変更すると、無効な参照となるため注意が必要です。

自動実行

Schedule to run repeatedly? からジョブの繰り返し実行のスケジュールを設定できます。
Crontab 形式での指定は、通常の crontab での設定とは異なり拡張されています。
秒 分 時 日 月 曜 年
先頭に秒、末尾に年が増えています。

以下は設定画面にある See: Cron reference for formatting helpリンク先からの転載です。
Quartz Scheduler を使っているのでしょうか?


Format

A cron expression is a string comprised of 6 or 7 fields separated by white space. Fields can contain any of the allowed values, along with various combinations of the allowed special characters for that field. The fields are as follows:
Field NameMandatoryAllowed ValuesAllowed Special Characters
SecondsYES0-59, - * /
MinutesYES0-59, - * /
HoursYES0-23, - * /
Day of monthYES1-31, - * ? / L W
MonthYES1-12 or JAN-DEC, - * /
Day of weekYES1-7 or SUN-SAT, - * ? / L #
YearNOempty, 1970-2099, - * /
So cron expressions can be as simple as this: * * * * ? *
or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2002-2010

Special characters

  • * ("all values") - used to select all values within a field. For example, "" in the minute field means *"every minute".
  • ? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field. See the examples below for clarification.
  • - - used to specify ranges. For example, "10-12" in the hour field means "the hours 10, 11 and 12".
  • , - used to specify additional values. For example, "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
  • / - used to specify increments. For example, "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". You can also specify '/' after the '' character - in this case '' is equivalent to having '0' before the '/'. '1/3' in the day-of-month field means "fire every 3 days starting on the first day of the month".
  • L ("last") - has different meaning in each of the two fields in which it is allowed. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
  • W ("weekday") - used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days.
The 'L' and 'W' characters can also be combined in the day-of-month field to yield 'LW', which translates to *"last weekday of the month"*.
  • # - used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means"the third Friday of the month" (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.
The legal characters and the names of months and days of the week are not case sensitive. MON is the same as mon.

実行結果

実行結果は履歴として残り、後からAcutivity画面を見れば確認できます。
結果には、実行時のワークフローの定義も一緒に記録されています。

過去の実行履歴をみると、その時、どのような定義のワークフローで実行したかもわかるようになっています。これは、ワークフローを後から変更したときでも、過去の実行履歴は独立した記録になっていて、影響を受けないということであり、大変重要なことです。

2015年2月6日金曜日

Rundeck プロジェクトの作成

プロジェクト

Rundeckではプロジェクトという単位で、実行対象のノードとジョブを管理します。

プロジェクトの作成

テストで使うプロジェクトをtest-driveという名前で作成します。

「New Project+」をクリックします。
プロジェクトの作成画面になります。
Project Name に、プロジェクト名 test-drive を指定します。
先ほど、SSHの鍵を作成しているのでほかの部分はデフォルトのままでかまいません。


「Create」ボタンを押せばプロジェクトが作成されます。

プロジェクト固有の鍵を使用する場合

鍵の登録

鍵を作成します。
% ssh-keygen -t dsa -f rundeck -N ''
Generating public/private dsa key pair.
Your identification has been saved in rundeck.
Your public key has been saved in rundeck.pub.
The key fingerprint is:
39:97:87:08:20:3c:4b:e7:d4:e9:04:c0:32:df:c3:06 komeda@ubuntu
The key's randomart image is:
+--[ DSA 1024]----+
| oo.oo .         |
|o E.o.+          |
| = X o.          |
|  o * .. o o     |
|   . .  S + .    |
|         o .     |
|                 |
|                 |
|                 |
+-----------------+

画面最上部の、 グローバルナビゲーションにあるギアマークをクリックして構成管理画面を開き、「Key Storage」を選択します。

「+Add or Upload a Key」から秘密鍵と公開鍵を登録します。

ここでは設定を簡単にするために鍵を作るときにパスフレーズは設定していません。もし設定するときは、パスフレーズも併せて登録するか、ジョブを定義するときにSecure Remote Authentication Optionを設定する必要があります。

プロジェクトで使用する鍵を指定する

プロジェクトの構成から「edit configration」で編集画面を開いて、「SSH Key Storage Path」で先ほど登録した秘密鍵を指定します。

設定するところは SSH と SCP の2カ所あります。同じ値を指定してください。

註) SSH Key Storage Path でプロジェクトの鍵を指定して、project.propertiesではproject.ssh-key-storage-pathが設定されているのに、GUIからは値が保存されないように見えることがありました。このようなときは、/var/rundeck/projects/test-drive/etc/project.propertiesの内容も確認するようにしてください。

SSH Key File pathとSSH Key Storage Pathの両方が指定されている場合には、SSH Key Storage Pathで指定した鍵が使用されます。

ノードの設定

プロジェクトのノードはプロジェクトのresources.xmlで指定します。GUIから直接登録することはできないので、ファイルを編集してください。
ファイルは/var/rundeck/projects/test-drive/etc/resources.xmlにあります。プロジェクトを作った後の初期状態ではRundeckサーバのみが登録されているはずです。
<?xml version="1.0" encoding="UTF-8"?>

<project>
  <node description="Rundeck server node" hostname="localhost" name="localhost" osarch="amd64" osfamily="unix" osname="Linux" osversion="3.13.0-24-generic" tags="" username="rundeck">
</node>
</project>

ここでは、ubuntu-hostというノードを追加しています。

<?xml version="1.0" encoding="UTF-8"?>

<project>
  <node description="Rundeck server node" hostname="localhost" name="localhost" osarch="amd64" osfamily="unix" osname="Linux" osversion="3.13.0-24-generic" tags="" username="rundeck">
</node>
  <node name="ubuntu-host" description="Rundeck server node" tags="" hostname="ubuntu-host" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.13.0-24-generic" username="rundeck"/>
</project>


追加したノードにはrundeckユーザを作成し、公開鍵でログインできるようにしておきます。
% cd ~rundeck/.ssh
% cat id_rsa.pub >>authorized_keys
% chown rundeck:rundeck authorized_keys 
% chmod go-rwx authorized_keys

ノードの登録時に属性として 
  • username="user1"
というように、ログインユーザを指定することもできます。

詳細はマニュアルを参照してください。該当ページを引用しておきます。

Specifying SSH Username

The username used to connect via SSH is taken from the username Node attribute:
  • username="user1"
This value can also include a property reference if you want to dynamically change it, for example to the name of the current Rundeck user, or the username submitted as a Job Option value:
  • ${job.username} - uses the username of the user executing the Rundeck execution.
  • ${option.someUsername} - uses the value of a job option named "someUsername".
If the username node attribute is not set, then the static value provided via project or framework configuration is used. The username for a node is determined by looking for a value in this order:
  1. Node levelusername node attribute. Can contain property references to dynamically set it from Option or Execution values.
  2. Project levelproject.ssh.user property in project.properties file for the project.
  3. Rundeck levelframework.ssh.user property in framework.properties file for the Rundeck installation.


つぎはジョブの作成と実行です。

Rundeck インストール編

インストール

Rundeckをインストールします。今回使った環境は Ubuntu Linux 14.04 です。
現在の最新版はVersion 2.4.1です。これより古い版では、コマンド実行時の出力にASCII以外の文字が含まれていると、実行結果をそのままの形で扱えませんでした。
マルチバイト文字を正しく扱うために最新版を使用しましょう。

本稿の環境

Ubuntu 14.04

準備

http://rundeck.org/downloads.html からパッケージを入手します。
Debian/Ubuntu Install
rundeck-2.4.1-1-GA.debExecute:
dpkg -i rundeck-2.4.1-1-GA.deb
ファイルのチェックサムを確認します。
% shasum rundeck-2.4.1-1-GA.deb 
5ce117bc994c6911bfbd46cc6a7f58b76e2e228f  rundeck-2.4.1-1-GA.deb

スーパーユーザになってパッケージをインストールします。
# dpkg -i rundeck-2.4.1-1-GA.deb  
Selecting previously unselected package rundeck.
(Reading database ... 58039 files and directories currently installed.)
Preparing to unpack rundeck-2.4.1-1-GA.deb ...
Unpacking rundeck (2.4.1) ...
dpkg: dependency problems prevent configuration of rundeck:
 rundeck depends on java6-runtime | java6-runtime-headless | java7-runtime | java7-runtime-headless; however:
  Package java6-runtime is not installed.
  Package java6-runtime-headless is not installed.
  Package java7-runtime is not installed.
  Package java7-runtime-headless is not installed.

dpkg: error processing package rundeck (--install):
 dependency problems - leaving unconfigured
Processing triggers for ureadahead (0.100.0-16) ...
Errors were encountered while processing:
 rundeck

残念ながらエラーになりました。

Rundeck はJavaアプリケーションであるため、Javaのランタイム環境が必要です。推奨パッケージも含め一括でインストールするため、aptitudeopenjdk-7-jreをインストールします。
# aptitude install openjdk-7-jre 
The following NEW packages will be installed:
  acl{a} at-spi2-core{a} ca-certificates-java{a} colord{a} cpp{a} 
  cpp-4.8{a} dbus-x11{a} dconf-gsettings-backend{a} dconf-service{a} 
  desktop-file-utils{a} fontconfig{a} fontconfig-config{a} 
  fonts-dejavu-core{a} fonts-dejavu-extra{a} gconf-service{a} 
  gconf-service-backend{a} gconf2{a} gconf2-common{a} gdisk{a} gvfs{a} 
  gvfs-common{a} gvfs-daemons{a} gvfs-libs{a} hicolor-icon-theme{a} 
  java-common{a} libasound2{a} libasound2-data{a} libasyncns0{a} 
  libatasmart4{a} libatk-bridge2.0-0{a} libatk-wrapper-java{a} 
  libatk-wrapper-java-jni{a} libatk1.0-0{a} libatk1.0-data{a} 
  libatspi2.0-0{a} libavahi-client3{a} libavahi-common-data{a} 
  libavahi-common3{a} libavahi-glib1{a} libbonobo2-0{a} 
  libbonobo2-common{a} libcairo-gobject2{a} libcairo2{a} libcanberra0{a} 
  libcloog-isl4{a} libcolord1{a} libcolorhug1{a} libcups2{a} libdatrie1{a} 
  libdconf1{a} libdrm-intel1{a} libdrm-nouveau2{a} libdrm-radeon1{a} 
  libexif12{a} libflac8{a} libfontconfig1{a} libfontenc1{a} libgconf-2-4{a} 
  libgconf2-4{a} libgd3{a} libgdk-pixbuf2.0-0{a} libgdk-pixbuf2.0-common{a} 
  libgif4{a} libgl1-mesa-dri{a} libgl1-mesa-glx{a} libglapi-mesa{a} 
  libgmp10{a} libgnome2-0{a} libgnome2-bin{a} libgnome2-common{a} 
  libgnomevfs2-0{a} libgnomevfs2-common{a} libgphoto2-6{a} 
  libgphoto2-l10n{a} libgphoto2-port10{a} libgraphite2-3{a} libgtk-3-0{a} 
  libgtk-3-bin{a} libgtk-3-common{a} libgtk2.0-0{a} libgtk2.0-bin{a} 
  libgtk2.0-common{a} libgudev-1.0-0{a} libgusb2{a} libharfbuzz0b{a} 
  libice6{a} libicu52{a} libidl-common{a} libidl0{a} libieee1284-3{a} 
  libisl10{a} libjasper1{a} libjbig0{a} libjpeg-turbo8{a} libjpeg8{a} 
  liblcms2-2{a} libllvm3.4{a} libltdl7{a} libmpc3{a} libmpfr4{a} 
  libnspr4{a} libnss3{a} libnss3-nssdb{a} libogg0{a} liborbit-2-0{a} 
  liborbit2{a} libpango-1.0-0{a} libpangocairo-1.0-0{a} 
  libpangoft2-1.0-0{a} libpciaccess0{a} libpixman-1-0{a} libpulse0{a} 
  libsane{a} libsane-common{a} libsecret-1-0{a} libsecret-common{a} 
  libsm6{a} libsndfile1{a} libtdb1{a} libthai-data{a} libthai0{a} 
  libtiff5{a} libtxc-dxtn-s2tc0{a} libudisks2-0{a} libv4l-0{a} 
  libv4lconvert0{a} libvorbis0a{a} libvorbisenc2{a} libvorbisfile3{a} 
  libvpx1{a} libwayland-client0{a} libwayland-cursor0{a} libx11-xcb1{a} 
  libxaw7{a} libxcb-dri2-0{a} libxcb-dri3-0{a} libxcb-glx0{a} 
  libxcb-present0{a} libxcb-render0{a} libxcb-shape0{a} libxcb-shm0{a} 
  libxcb-sync1{a} libxcomposite1{a} libxcursor1{a} libxdamage1{a} 
  libxfixes3{a} libxft2{a} libxi6{a} libxinerama1{a} libxkbcommon0{a} 
  libxmu6{a} libxpm4{a} libxrandr2{a} libxrender1{a} libxshmfence1{a} 
  libxt6{a} libxtst6{a} libxv1{a} libxxf86dga1{a} libxxf86vm1{a} 
  openjdk-7-jre openjdk-7-jre-headless{a} policykit-1-gnome{a} 
  sound-theme-freedesktop{a} tzdata-java{a} udisks2{a} x11-common{a} 
  x11-utils{a} 
The following packages will be upgraded:
  tzdata 
The following partially installed packages will be configured:
  rundeck 
1 packages upgraded, 168 newly installed, 0 to remove and 8 not upgraded.
Need to get 241 kB/83.8 MB of archives. After unpacking 257 MB will be used.
Do you want to continue? [Y/n/?] 
(中略)
Current status: 0 broken [-1], 8 updates [-1].

JREがインストールできたので、Rundeckのパッケージをインストールします。
# dpkg -i rundeck-2.4.1-1-GA.deb  
(Reading database ... 66206 files and directories currently installed.)
Preparing to unpack rundeck-2.4.1-1-GA.deb ...
Unpacking rundeck (2.4.1) over (2.4.1) ...
Setting up rundeck (2.4.1) ...
usermod: no changes
Processing triggers for ureadahead (0.100.0-16) ...

インストールできました。サービスを起動します。
# service rundeckd start
rundeckd start/running, process 58776

起動には少し時間がかかります。ログが/var/log/rundeck/service.logに出力されているので確認してみます。
# tail /var/log/rundeck/service.log 
2015-01-30 23:23:56.852:INFO:oejs.Server:jetty-7.6.0.v20120127
2015-01-30 23:23:58.750:INFO:oejw.StandardDescriptorProcessor:NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
2015-01-30 23:23:59.925:INFO:/:Initializing Spring root WebApplicationContext
INFO  BootStrap: Starting Rundeck 2.4.1-1...
INFO  BootStrap: using rdeck.base config property: /var/lib/rundeck
INFO  BootStrap: loaded configuration: /etc/rundeck/framework.properties
INFO  BootStrap: RSS feeds disabled
2015-01-30 23:24:20.216:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/var/lib/rundeck/exp/webapp/},/var/lib/rundeck/exp/webapp
2015-01-30 23:24:20.271:INFO:/:Initializing Spring FrameworkServlet 'grails'
2015-01-30 23:24:20.354:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:4440

oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:4440
が出力されていれば起動が完了しています。

古いバージョンのパッケージを使ったときに、インストール後のいくつかアクセス権の設定がおかしく、エラーが出ているかもしれません。筆者が試したときは /tmp/rundeck の所有者が root ユーザになって書き込みエラーが出ていました。正しくは rundeck ユーザが所有者であるべきですので、修正してください。
chown rundeck:rundeck /tmp/rundeckchmod 750 /tmp/rundeck

初期設定

デフォルトでは、Rundeck サービスのアクセス URL が
http://localhost:4440
になっています。ソケット自体はIN6ADDR_ANY_INIT でバインドしているため、どこからでもアクセスできるのですが、ログイン認証の後このURLにリダイレクトされてしまうため操作が継続できないと思います。

本稿では、SSH のダイナミックポートフォワードを利用して、Socks5プロキシ経由でアクセスしているため、このURLのままでも問題がないのですが、ほとんどの場合、デフォルトのままでは都合が悪いと思われます。

/etc/rundeck/rundeck-config.properties に設定がありますのでこれを修正してください。
grails.serverURL=http://localhost:4440
修正後
grails.serverURL=http://ホスト名orIPアドレス:4440

I18N

デフォルトの設定ではコマンド出力がUTF-8なマルチバイトの文字を含むと、そこが ? に置換されてしまいます。rundeckdの実行時のcharsetがUTF-8になるように、/etc/rundeck/profileで
LANG=en_US.UTF-8
export LANG
あるいは
LANG=ja_JP.UTF-8
export LANG
を設定して起動する必要があります。

注意

古い版では、そもそもマルチバイトな文字列が扱えませんでした。この問題はv2.4.1で修正されていますので、v2.4.1以上を使うようにしてください。

ログイン

初期アカウントは、ユーザ名、パスワード共に admin です。


ログインできればこのような画面が表示されるでしょう。

ユーザアカウント

認証情報は/etc/rundeck/realm.propertiesで設定します。

形式は次の通りです。
<username>:<password>[,<rolename> ...]

初期状態ではadminユーザのデフォルトパスワードは平文で書かれていますが、これを秘匿するには次のようにします。
# java -cp /var/lib/rundeck/bootstrap/jetty-all-7.6.0.v20120127.jar org.eclipse.jetty.util.security.Password username password

Rundeckの管理者マニュアルに書かれているコマンドは古いJettyのときのものなので使用できません。現在のJetty 7での方法はこちらを参照してください。
https://wiki.eclipse.org/Jetty/Howto/Secure_Passwords
MD5の形式でよければ、つぎのワンライナーでも作成できます。
printf "MD5:%s" $(read -sp "Password: " passwd; echo "$passwd") | md5sum

実行例

# java -cp /var/lib/rundeck/bootstrap/jetty-all-7.6.0.v20120127.jar org.eclipse.jetty.util.security.Password admin admin
admin
OBF:1u2a1toa1w8v1tok1u30
MD5:21232f297a57a5a743894a0e4a801fc3
CRYPT:adpexzg3FUZAk

出力の OBF:, MD5:, CRYPT: 行のいずれかを<password>として設定します。ハッシュ形式を示すOBF:, MD5:, CRYPT:の部分も必要です。

admin:MD5:21232f297a57a5a743894a0e4a801fc3,user,admin,architect,deploy,build

ファイルを変更すると、つぎの認証からは新しい値が使用されます。サービスの再起動は不要です。

SSH 鍵の作成

Rundeckがコマンド実行際に使用するデフォルトのSSH鍵を作成しておきます。
プロジェクトごとに認証に使用する鍵を指定することができますので、からなずしもこの鍵を使う必要はありません。

# mkdir /var/lib/rundeck/.ssh
# chown rundeck:rundeck /var/lib/rundeck/.ssh
# chmod go-rwx /var/lib/rundeck/.ssh
# ssh-keygen -t rsa -f /var/lib/rundeck/.ssh/id_rsa -N '' -C Rundeck
Generating public/private rsa key pair.
Your identification has been saved in /var/lib/rundeck/.ssh/id_rsa.
Your public key has been saved in /var/lib/rundeck/.ssh/id_rsa.pub.
The key fingerprint is:
83:06:12:c0:bc:29:96:b3:1b:ae:c7:f8:71:b9:53:37 Rundeck
The key's randomart image is:
+--[ RSA 2048]----+
|+..              |
| o .             |
|  = .            |
|.* . . .         |
|o o   o S        |
| o   o. E.       |
|.o+ o. . .       |
|.ooo..           |
|oo. ..           |
+-----------------+
# chown rundeck:rundeck /var/lib/rundeck/.ssh/id_rsa*

つぎはプロジェクトの作成をします。