Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a file locally with ansible templates on the development machine

Tags:

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.

I want to use ansible templates locally to create some generic files. But how would i take ansible to execute something locally?

I read something with local_action but i guess i did not get this right.

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
like image 950
Jurudocs Avatar asked Aug 31 '25 22:08

Jurudocs


1 Answers

You can delegate tasks with the parameter 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

See Playbook Delegation in the docs.

For localhost you additionally need to ensure local connection in your inventory:

[local]
localhost   ansible_connection=local
like image 193
udondan Avatar answered Sep 03 '25 21:09

udondan