テンプレートがリモートホスト上にある場合は、2つのオプションがあります。
copyモジュールの反対側のモジュールとして動作するfetchモジュールを使用すると、リモートホスト上のレポを複製した後にテンプレートを戻すことができます。タスクはそれだけで、それはに対して実行する最初のホストからテンプレートをコピーする気になることを確認するrun_once
を使用してフェッチ
- name : clone repo on remote hosts
git :
repo : {{ git_repo_src }}
dest : {{ git_repo_dest }}
- name : fetch template from single remote host
run_once : true
fetch :
src : {{ template_path }}/{{ template_file }}
dest : /tmp/{{ template_file }}
flat : yes
fail_on_missing : yes
- name : template remote hosts
template :
src : /tmp/{{ template_file }}
dest : {{ templated_file_dest }}
owner : {{ templated_file_owner }}
group : {{ templated_file_group }}
mode : {{ templated_file_mode }}
:このため
脚本は、次のようになります。プレイ中のこれらのホストすべてが同じリポジトリを取得していると仮定すると、これはうまくいくはずですが、非常に特定のホストからコピーしたことを確認する必要がある場合は、delegate_to
と組み合わせることができます。
代わりにあなただけのローカルレポをAnsibleクローンを持っている可能性があり、のようなもので、それを直接使用します。なぜAnsibleは同様にあなたの他のレポを引くことを可能
- name : clone repo on remote hosts
git :
repo : {{ git_repo_src }}
dest : {{ git_repo_dest }}
- name : clone repo on Ansible host
hosts : localhost
connection : local
git :
repo : {{ git_repo_src }}
dest : {{ git_repo_local_dest }}
- name : template remote hosts
template :
src : {{ template_local_src }}
dest : {{ templated_file_dest }}
owner : {{ templated_file_owner }}
group : {{ templated_file_group }}
mode : {{ templated_file_mode }}
? – ydaetskcoR
リモートサーバへのリポジトリを複製します。クローンが作成されたら、リポジトリにあったテンプレートを使用して変更を加える必要があります。これはリモートマシン上にあります。 – trajan
はい、なぜAnipalはローカルでリポジトリをプルするだけでなく、ターゲットホストでクローンを作成できないのですか?次に、テンプレート機能を使用できます。あなたの代わりに 'fetch'を使ってホストからテンプレートを取り戻すことができますが、私にとってはそれほどクリーンではない方法のように感じます。 – ydaetskcoR