robertdebock.service
Ansible ロール サービス
Linux システムにカスタムサービスを追加します。
GitHub | GitLab | ダウンロード | バージョン |
---|---|---|---|
例のプレイブック
この例は molecule/default/converge.yml
から取られ、各プッシュ、プルリクエスト、リリースでテストされます。
---
- name: Converge
hosts: all
become: true
gather_facts: true
vars:
_service_test_command:
default: /usr/bin/sleep
Alpine: /bin/sleep
Debian: /bin/sleep
Ubuntu-16: /bin/sleep
Ubuntu-18: /bin/sleep
service_test_command: "{{ _service_test_command[ansible_distribution ~ '-' ~ ansible_distribution_major_version] | default(_service_test_command[ansible_os_family] | default(_service_test_command['default'])) }}" # noqa 204 Just long.
roles:
- role: robertdebock.service
service_list:
- name: simple-service
description: シンプルサービス
start_command: "{{ service_test_command }} 3600"
state: started
enabled: true
- name: stopped-service
description: シンプルサービス
start_command: "{{ service_test_command }} 3601"
state: stopped
enabled: false
- name: specific-stop-service
description: 特定の停止サービス
start_command: "{{ service_test_command }} 1440"
stop_command: /usr/bin/killall -f "sleep 1440"
- name: specific-user-group-service
description: 特定のユーザーグループサービス
start_command: "{{ service_test_command }} 28800"
user_name: root
group_name: root
- name: specific-workingdirectory-service
description: 特定の作業ディレクトリサービス
start_command: "{{ service_test_command }} 57600"
working_directory: /tmp
- name: specific-pattern-service
description: 特定のステータスパターンサービス
start_command: "{{ service_test_command }} 115200"
status_pattern: 115200
- name: variable-service
description: 環境変数を持つサービス
start_command: "{{ service_test_command }} ${time}"
environment_variables:
time: 230400
- name: pidfile-service
description: pidファイルを持つサービス
start_command: "{{ service_test_command }} 460800"
pidfile: /var/run/pidfile-service.pid
- name: environmentfile-service
description: 環境ファイルを持つサービス
start_command: "{{ service_test_command }} 921600"
environmentfile: /environmentfile.txt
マシンを準備する必要があります。CIでは、molecule/default/prepare.yml
を使用して行います:
---
- name: Prepare
hosts: all
become: true
gather_facts: false
serial: 30%
roles:
- role: robertdebock.bootstrap
post_tasks:
- name: /environmentfile.txt を配置
ansible.builtin.copy:
content: "value=variable"
dest: /environmentfile.txt
mode: "0644"
これらのロールの使い方については、完全な説明と例 をご覧ください。
ロール変数
変数のデフォルト値は defaults/main.yml
に設定されています:
---
# サービス用のデフォルトファイル
# service_list にはシステムに追加するサービスのリストを含めることができます。
# 各アイテムの必須項目は以下の通りです:
# - name: サービスの(短い)名前、例えば「tomcat」。
# - description: もう少し長い名前、例えば「Tomcat アプリケーションサーバ」。
# - start_command: デーモンを起動するためのコマンド、
# 例えば「/usr/local/bin/java -jar some.jar」
# オプション項目は以下の通りです:
# - stop_command: デフォルトでは、起動されたプログラムが見つかり停止します。
# 実行中のプログラムが名前を変更したり、起動中にパスが変更された場合に
# カスタム停止コマンドを指定できます。例えば「pkill foo」
# - status_pattern: プログラムのステータスを確認する際に探すプログラム(またはパターン)、例えば「artifactory」。
# - type: プログラムの起動方法;「simple」または「forking」。シンプルはプログラムがフォアグラウンドで実行されることを意味します。
# - working_directory: サービスを開始する前に移動するディレクトリ。
# - environment_variables: 設定する変数のリスト。例:
# environment_variables:
# variable1: value1
# variable2: value2
# - after: 指定されたサービスの後に起動。
# - restart_mode: 使用するモード、例えば「always」。
# - restart_seconds: 再起動が完了するまでの待機時間。
service_list: []
要件
- requirements.txt にリストされた pip パッケージ。
使用されるロールのステータス
以下のロールがシステムの準備に使用されます。他の方法でシステムを準備することもできます。
要件 | GitHub | GitLab |
---|---|---|
robertdebock.bootstrap |
コンテキスト
このロールは多くの互換ロールの一部です。さらに詳細については、これらのロールのドキュメントをご覧ください。
関連するロールの概要:
互換性
このロールは以下の コンテナイメージ でテストされています:
コンテナ | タグ |
---|---|
EL | 9 |
Debian | すべて |
Fedora | すべて |
Ubuntu | すべて |
必要な最低限の Ansible のバージョンは 2.12 であり、テストは:
- 前のバージョン。
- 現在のバージョン。
- 開発バージョン。
問題が見つかった場合は、GitHub に報告してください。
ライセンス
著者情報
私を サポートすること を検討してください。
インストール
ansible-galaxy install robertdebock.service
ライセンス
apache-2.0
ダウンロード
351.7k
所有者
I know my way around (Linux) infrastructure, have a passion for automation, Docker, Ansible, Molecule and ci/cd.