OpenSource-Hub

ansible

CLI ツール

ansible/ansible

デプロイと構成管理のためのエージェントレスな IT 自動化プラットフォーム。

概要

Ansible は SSH を介してエージェントレスな自動化を提供し、マシン管理、アプリケーションのデプロイ、マルチノードオーケストレーションをサポートします。読みやすい YAML プレイブックを使用し、Infrastructure as Code をサポートします。

README プレビュー

[](https://pypi.org/project/ansible-core)\n[](https://docs.ansible.com/ansible/latest/)\n[](https://docs.ansible.com/ansible/devel/community/communication.html#real-time-chat)\n[](https://docs.ansible.com/ansible/devel/community/communication.html#forum)\n[](https://dev.azure.com/ansible/ansible/_build/latest?definitionId=20&branchName=devel)\n[](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html)\n[][copying]\n[](https://bestpractices.coreinfrastructure.org/projects/2372)\n\n# Ansible\n\nAnsible is a radically simple IT automation system. It handles\nconfiguration management, application deployment, cloud provisioning,\nad-hoc task execution, network automation, and multi-node orchestration. Ansible makes complex\nchanges like zero-downtime rolling updates with load balancers easy. More information on the Ansible [website](https://ansible.com/).\n\n## Design Principles\n\n* Have an extremely simple setup process with a minimal learning curve.\n* Manage machines quickly and in parallel.\n* Avoid custom-agents and additional open ports, be agentless by\n  leveraging the existing SSH daemon.\n* Describe infrastructure in a language that is both machine and human\n  friendly.\n* Focus on security and easy auditability/review/rewriting of content.\n* Manage new remote machines instantly, without bootstrapping any\n  software.\n* Allow module development in any dynamic language, not just Python.\n* Be usable as non-root.\n* Be the easiest IT automation system to use, ever.\n\n## Use Ansible\n\nYou can install a released version of Ansible with `pip` or a package manager. See our\n[installation guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) for details on installing Ansible\non a variety of platforms.\n\nPower users and developers can run the `devel` branch, which has the latest\nfeatures and fixes, directly. Although it is reasonably stable, you are more likely to encounter\nbreaking changes when running the 

FAQ (5)

トラブル対応
Python 3.15でansible-galaxyまたはansibleを実行した際に発生する「AttributeError: module dataclasses has no attribute _is_type」を修正する方法

このエラーは、ansible-core 2.21 が Python 3.15 で削除された内部の dataclasses._is_type API に依存しており、ansible-core 2.21 が Python 3.15 をサポートしていないために発生します。修正方法: (1) Python 3.15 を公式にサポートした最初のバージョンである ansible-core 2.22 以降にアップグレードしてください(PR #86976 で修正済み): pip install --upgrade ansible-core>=2.22。(2) または、ansible-core 2.21 に対応した Python バージョン(例: 3.14 以下)にインタープリターをダウングレードしてください。2.21 へのバックポートは予定されていないため、ansible-core をアップグレードするか、Python をダウングレードするかが唯一の選択肢です。

参照 Issue #87677
トラブル対応
Ubuntu 26.04 で --become を使用した際に Ansible の「Timeout waiting for privilege escalation prompt」エラーが発生する場合の修正方法

これは、Ansible が権限昇格に誤った sudo 実行ファイルを選択するため、Ubuntu 26.04 上の ansible-core 2.21.x に影響します。become 実行ファイルを明示的に /usr/bin/sudo.ws に設定することで、この問題を回避できます:

ansible -i hosts.ini ubuntu26 -a "ls" -k -K -b -e ansible_become_exe=/usr/bin/sudo.ws

あるいは、インベントリで設定することもできます:

[ubuntu26]
your-host ansible_become_exe=/usr/bin/sudo.ws

そのパスに存在しない場合は、command -v sudo.ws でパスを確認してください。この問題は Ansible の devel ブランチで修正されており、バックポート/修正 PR には #86905 と #86964 が含まれます。そのため、この修正を含む ansible-core リリースが利用可能になったらアップグレードしてください。

参照 Issue #87423
トラブル対応
非文字列のデフォルト値を持つ Ansible の no_log オプションで発生する "'bool' object has no attribute 'strip'" エラーを修正する方法

これは ansible-core 2.22.0b2 および影響を受ける devel ビルド (#87457) におけるリグレッションです。ansible-core 2.21 は影響を受けません。issue #87623 の修正を含むリリースまたは devel ビルドにアップグレードするか、一時的に ansible-core 2.21 にダウングレードしてください。

モジュールの回避策として、文字列以外のデフォルト値を持つ、シークレットではない boolean、integer、または port オプションから no_log=True を削除してください。例:

# 変更前
force=dict(type='bool', no_log=True, default=True)

# 変更後
force=dict(type='bool', default=True)

同じ変更は no_log サブオプションおよびロールの argument_specs にも適用されます。パッチが適用された Ansible バージョンでは、文字列以外のデフォルト値が正しく処理され、boolean の True/False 値のマスキングがスキップされます。

参照 Issue #87623
トラブル対応
同じプレイ内で、あるホストのansible_factsが別のホストに漏洩するのを防ぐにはどうすればよいですか?

これは、ansible-core 2.21.x の VariableManager.set_host_facts() におけるホスト間の辞書エイリアシングが原因で発生します。特に複数のホストや run_once タスクがある場合に起こりやすくなります。この修正では、呼び出し元の dict 参照をそのまま格納するのではなく、キャッシュする前に facts 辞書をコピーします。PR #87415 を含む ansible-core リリースにアップグレードするか、そのパッチを手動で適用してください。

確実な回避策として、ansible.builtin.setup を明示的に呼び出し、register を使用して、暗黙的な ansible_facts ではなく登録された変数から facts を読み取ってください。

- name: Gather host facts
  ansible.builtin.setup:
  register: host_setup

- name: Use registered facts
  ansible.builtin.debug:
    var: host_setup.ansible_facts.ansible_default_ipv4.address

forks、strategy、callbacks を変更したり、--flush-cache を実行しても、facts がメモリ上でエイリアスされているため、この問題は解決しません。

参照 Issue #87415
トラブル対応
なぜ FreeBSD で `ansible.builtin.service` を使用した場合、無効化されているサービスに対して `state: restarted` が効果を持たないのですか?

FreeBSD では、service モジュールは無効化されたサービスに対して start、stop、reload をそれぞれ対応する one* 系のコマンドにマッピングしますが、restart は onerestart にマッピングされません。そのため、無効化されたサービスは再起動されません。

回避策: FreeBSD の onerestart を直接呼び出します:

- name: 無効化された FreeBSD サービスを強制的に再起動する
  become: true
  ansible.builtin.command:
    cmd: /usr/sbin/service apache24 onerestart
  changed_when: true

別の方法として、再起動する前にサービスを有効化することもできます:

- name: apache24 を有効化して再起動する
  become: true
  ansible.builtin.service:
    name: apache24
    enabled: true
    state: restarted

アップストリームでのコード修正は、restart アクションを同じ方法でマッピングすることです:

if self.action == "restart":
    self.action = "onerestart"

参照 Issue #84793