> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/deploy-device-protection-with-ansible.md).

# Ansible を使用してデバイス保護を展開する

SSHで配布しているLinuxの群れ全体にDevice Protectionをインストールするには、Ansibleを使います。下のロールは各ホストに適したパッケージを選び、ユーザーグループのトークンでインストールし、サービスを有効化したままにします。

読む [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md) まず、トークン、パッケージ、そして各方式で使われるインストールオプションについて。 [Linux 展開リファレンス](/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/linux-rollout-reference.md) では、トークンの扱い、再起動、繰り返し実行、デバイス ID について残りを説明します。

## ロールの構成

```
roles/aikido_device_protection/
├── defaults/main.yml
├── handlers/main.yml
└── tasks/main.yml
group_vars/
└── developer_workstations.yml
site.yml
```

## ロールを設定する

{% stepper %}
{% step %}
**デフォルトを追加する**

{% code title="roles/aikido\_device\_protection/defaults/main.yml" %}

```yaml
---
aikido_release_url: https://github.com/AikidoSec/safechain-internals/releases/latest/download

# インストール後に再起動します。既定ではオフです。手順3を参照してください。
aikido_reboot: false
```

{% endcode %}
{% endstep %}

{% step %}
**タスクを追加する**

最初のタスクは、やることがあるかどうかを判断するので、繰り返し実行しても安価で、トークンに触れることはありません。

{% code title="roles/aikido\_device\_protection/tasks/main.yml" %}

```yaml
---
- name: Device Protection がすでにインストールされているか確認する
  ansible.builtin.command: aikido-doctor --simple
  register: aikido_installed
  changed_when: false
  failed_when: false

- name: Device Protection をインストールする
  when: aikido_installed.rc != 0
  ブロックで参照します:
    - name: パッケージのアーキテクチャを決める
      ansible.builtin.set_fact:
        aikido_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'amd64' }}"

    - name: パッケージ名を決める
      ansible.builtin.set_fact:
        aikido_package: >-
          {{
            'EndpointProtection-' ~ aikido_arch ~ '.deb'
            if ansible_facts['os_family'] == 'Debian'
            else 'EndpointProtection-' ~ aikido_arch ~ '.el'
                 ~ ansible_facts['distribution_major_version'] ~ '.rpm'
          }}

    - name: パッケージをダウンロードする
      ansible.builtin.get_url:
        url: "{{ aikido_release_url }}/{{ aikido_package }}"
        dest: "/tmp/{{ aikido_package }}"
        mode: "0600"

    - name: Debian と Ubuntu にパッケージをインストールする
      ansible.builtin.apt:
        deb: "/tmp/{{ aikido_package }}"
      environment:
        AIKIDO_TOKEN: "{{ aikido_token }}"
      no_log: true
      when: ansible_facts['os_family'] == 'Debian'
      notify: Device Protection を有効化するため再起動

    - name: RHEL、Rocky Linux、CentOS にパッケージをインストールする
      ansible.builtin.dnf:
        name: "/tmp/{{ aikido_package }}"
        state: present
      environment:
        AIKIDO_TOKEN: "{{ aikido_token }}"
      no_log: true
      when: ansible_facts['os_family'] == 'RedHat'
      notify: Device Protection を有効化するため再起動

    - name: ダウンロードしたパッケージを削除する
      ansible.builtin.file:
        path: "/tmp/{{ aikido_package }}"
        state: absent

- name: サービスが有効で実行中であることを確認する
  ansible.builtin.systemd_service:
    name: aikido-endpoint-protection
    state: started
    enabled: true
```

{% endcode %}

残したまま `gather_facts` がオンなら、ロールにはそれが必要です。 `distribution_major_version` は、次を選択するものです `el9` または `el10` ビルドです。

その `environment` keyword は、 [インストールにトークンを渡すものです](/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/linux-rollout-reference.md#how-the-token-reaches-the-package)、および `no_log: true` プレイブックの出力に表示されないようにします。
{% endstep %}

{% step %}
**再起動ハンドラーを追加する**

{% code title="roles/aikido\_device\_protection/handlers/main.yml" %}

```yaml
---
- name: Device Protection を有効化するため再起動する
  ansible.builtin.reboot:
    reboot_timeout: 600
    msg: Aikido Device Protection を有効化するため再起動しています
  when: aikido_reboot | bool
```

{% endcode %}

設定 `aikido_reboot: true` 誰も作業していないホスト向けです。開発用マシンではオフのままにし、人にログアウトしてから再度ログインするよう依頼してください。参照 [保護が有効になるとき](/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/linux-rollout-reference.md#when-protection-becomes-active).
{% endstep %}

{% step %}
**トークンを Ansible Vault に保存する**

Aikido のユーザーグループに対応するインベントリグループ用に、トークンを暗号化します:

{% code overflow="wrap" %}

```bash
ansible-vault encrypt_string --name aikido_token '<your-token>'
```

{% endcode %}

出力をグループの変数に貼り付けます:

{% code title="group\_vars/developer\_workstations.yml" %}

```yaml
---
aikido_token: !vault |
  $ANSIBLE_VAULT;1.1;AES256
  62313365396662343061393464336163383764373764613633653634306231386433626436623361
  ...
```

{% endcode %}

複数のユーザーグループを使う場合は、グループごとに繰り返します。各グループにはそれぞれ専用のトークンと専用の `group_vars` ファイル。

{% hint style="info" %}
トークンがすでに CI シークレットにある場合は、暗号化したコピーをコミットする代わりに、コントローラーの環境から読み込みます: `aikido_token: "{{ lookup('env', 'AIKIDO_TOKEN') }}"`.
{% endhint %}
{% endstep %}

{% step %}
**プレイブックを書いて実行する**

{% code title="site.yml" %}

```yaml
---
- name: Aikido Device Protection をデプロイする
  hosts: developer_workstations
  become: true
  serial: 20%
  roles:
    - aikido_device_protection
```

{% endcode %}

少数のマシンから始めて、徐々に広げます:

{% code overflow="wrap" %}

```bash
ansible-playbook site.yml --ask-vault-pass --limit pilot
ansible-playbook site.yml --ask-vault-pass
```

{% endcode %}
{% endstep %}
{% endstepper %}

## 展開を検証する

{% code overflow="wrap" %}

```bash
ansible developer_workstations -m command -a "aikido-doctor --simple"
ansible developer_workstations -b -m command -a "systemctl is-active aikido-endpoint-protection"
```

{% endcode %}

その後、デバイスはあなたの [デバイス一覧](https://app.aikido.dev/endpoint-protection/devices) に **Active** ステータスで表示されます。

## トラブルシューティング

| 問題                                                   | 対処                                                                                                                                                                                                                         |
| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| パッケージはインストールされるが、デバイスがダッシュボードに表示されない                 | `AIKIDO_TOKEN` インストールコマンドに対して設定されていませんでした。構成管理ツールはローカル環境をホストに引き継がないため、変数はタスク自体に設定し、その後パッケージをもう一度インストールしてください                                                                                                               |
| `apt` または `dnf` ファイルをインストールするのではなく、リポジトリ内でパッケージを探します | 名前ではなくパスを指定してください： `apt install ./EndpointProtection-amd64.deb`。先頭の `./` が、パッケージマネージャーにそれをローカルファイルとして扱わせます                                                                                                                 |
| Red Hat系ホストでインストールが失敗する                              | ビルドをメジャーバージョンに合わせてください。 `el9` バージョン9ではこのパッケージを、そして `el10` バージョン10ではこのパッケージを                                                                                                                                                |
| サービスが実行されていません                                       | 実行してください `systemctl status aikido-endpoint-protection`、次に `sudo aikido-doctor diagnostics` 詳細を送信するには                                                                                                                       |
| Node.js または uv が引き続き Aikido の証明書を拒否する                | インストールすると設定される `NODE_EXTRA_CA_CERTS` と `UV_SYSTEM_CERTS` システム全体に適用され、既に起動しているシェルはそれらを読み込みません。新しいログインシェルを開くか、デバイスを再起動してください                                                                                                 |
| トークンが実行結果やログに表示される                                   | ツールの秘匿機能を使用してください： `no_log` Ansible では、 `sensitive true` Chef では、 `Sensitive()` Puppet では                                                                                                                                  |
| 複数のマシンがデバイス一覧の1つのエントリを共有している                         | 同じものを使って起動しました `/etc/machine-id`。Linux のデバイスIDはそのファイルに従うため、複製元のイメージでそれを削除し、初回起動時に systemd に新しいものを書き込ませてください                                                                                                                |
| トレイアイコンが表示されない                                       | Ubuntu 以外の GNOME では想定内で、見た目だけの問題です。参照： [Linux でのトレイアイコンのサポート](/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux/tray-icon-support-on-linux.md) |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/aikido-debaisu/deploying-aikido-endpoint/device-protection-mdm-guides/linux/deploy-device-protection-with-ansible.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
