如何在开发机器上使用ansible模板在本地创建文件 [英] How to create a file locally with ansible templates on the development machine

查看:24
本文介绍了如何在开发机器上使用ansible模板在本地创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 ansible 开始,我正在寻找一种方法来使用 ansible playbook 在服务器和本地环境上创建样板项目.

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.

这是给 webbserver 的……但是我如何使用它并在本地创建一些文件?

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

请参阅文档中的剧本委托.

如果您的剧本通常应该在本地运行并且不涉及外部主机,您可以简单地创建一个包含 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆