如何在开发机器上使用Ansible模板在本地创建文件 [英] How to create a file locally with ansible templates on the development machine
问题描述
我从ansible开始,我正在寻找一种使用ansible剧本在服务器和本地环境上创建样板项目的方法.
I'm starting out with ansible and I'm looking for a way to create a boilerplate project on the server and on the local environment with ansible playbooks.
我想在本地使用ansible模板来创建一些通用文件. 但是我怎么会在本地执行某些事情呢?
I want to use ansible templates locally to create some generic files. But how would i take ansible to execute something locally?
我用local_action读了一些东西,但我想我没听错.
I read something with local_action but i guess i did not get this right.
这是用于Web服务器的...但是我该如何在本地创建一些文件?
This is for the webbserver...but how do i take this and create some files locally?
- hosts: webservers
remote_user: someuser
- name: create some file
template: src=~/workspace/ansible_templates/somefile_template.j2 dest=/etc/somefile/apps-available/someproject.ini
推荐答案
您可以将参数为delegate_to
的任务委派给您喜欢的任何主机,例如:
You can delegate tasks with the param delegate_to
to any host you like, for example:
- name: create some file
template: src=~/workspace/ansible_templates/somefile_template.j2 dest=/etc/somefile/apps-available/someproject.ini
delegate_to: localhost
请参阅文档中的 Playbook授权.
如果您的剧本通常应该在本地运行并且不涉及任何外部主机,则可以简单地创建一个包含localhost
的组,然后对该组运行该剧本.在您的库存中:
If your playbook should in general run locally and no external hosts are involved though, you can simply create a group which contains localhost
and then run the playbook against this group. In your inventory:
[local]
localhost ansible_connection=local
,然后在您的剧本中:
hosts: local
这篇关于如何在开发机器上使用Ansible模板在本地创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!