tra*_*jan 19 ansible ansible-playbook
我有存储在项目存储库中的配置文件的模板.我想要做的是在从存储库克隆项目之后,使用Ansible的模板模块在远程服务器上使用该模板创建配置文件.
查看模板模块的文档,似乎该src
属性仅支持本地文件.
我想避免使用我的Ansible playbook存储配置模板,因为我更有意义的是将这些项目特定模板保存在项目存储库中.
我可以使用模板模块的替代方案吗?
yda*_*coR 25
如果您的模板将在远程主机上,那么您有两个选项.
首先,您可以使用fetch模块,它与复制模块完全相反,在克隆远程主机上的repo后将模板带回.
这个剧本可能看起来像:
- 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 }}
Run Code Online (Sandbox Code Playgroud)
获取任务用于run_once
确保它只是困扰从其运行的第一个主机复制模板.假设您游戏中的所有这些主机都获得相同的回购,那么这应该没问题,但如果您需要确保从特定主机复制它,那么您可以将它与它结合使用delegate_to
.
或者,您可以让Ansible在本地克隆repo并直接使用它,例如:
- 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 }}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7012 次 |
最近记录: |