2017-11-26 6 views
-1

UbuntuとCentOSマシンの両方でNagiosをインストールするためのプレイブックがあるとします。どのように基本台帳に応じてプレイブックを呼び出すことができますか?ベースマシンに応じてプレイブックを実行できますか?

Ubuntuマシンの場合はnagios_ubuntuプレイブック、CentOSの場合はnagios_centosプレイブックをロードします。 http://docs.ansible.com/ansible/latest/playbooks_conditionals.html#applying-when-to-roles-imports-and-includes このの:

include: ubuntu.yml 
when: ansible_distribution == "Debian" 

include: centos.yml 
when: ansible_distribution == "Centos" 

はこのことを認識して:あなたはこのような何か行うことができます

+0

あなたの責任において、「負荷」は何を意味しますか? –

答えて

0

まず、あなたははホスト向けハンドブックを含めることはできません 。 Playbookの内部にはhostsディレクティブが定義されています。このケースでは、動的に使用することをお勧めします、あなたはタスクが異なるのOSのために含めることができますplaybook/tasks include

を参照してくださいあなたの脚本でステートメントを含める:

- include_tasks: "nagios_{{ ansible_os_family | lower }}.yml" 
0

あなたはgroup_byBest Practicesセクションで説明した例を利用することができます。

あなたはまだ、たとえば、自身が適切なhosts宣言を格納するためのプレイブックを変更する必要があります:

nagios_centos.yml

--- 
- hosts: nagios_centos 
# ... the rest of the play 

nagios_ubuntu.yml

--- 
- hosts: nagios_ubuntu 
# ... the rest of the play 

メイン脚本:

--- 
- hosts: all 
    tasks: 
    - group_by: 
     key: nagios_{{ ansible_os_family | lower }} 

- import_playbook: nagios_centos.yml 

- import_playbook: nagios_ubuntu.yml 

hostsの定義のため、1つのプレイブックだけが効果的に動作します。

関連する問題