6

I have to make delete some directory and create them on local before copy to the remote. Is there anyway to delete and create locally?

Currently I'm using 'command'

command: rm -r directory 

But warning shows as

Consider using file module with state=absent rather than running rm 

Is there any options we can use for local folder changes?

3 Answers 3

17

You can use diffrent delegation methods or use the local_action:

- local_action: file path=directory state=absent 
Sign up to request clarification or add additional context in comments.

Comments

2

If you're running this in a playbook, you can use a section of the playbook that uses a local connection to make changes on the command machine, then copies files to the remote:

--- - hosts: 127.0.0.1 connection: local tasks: - name: Delete local directory file: path=/directory state=absent - hosts: myhosts tasks: copy: src=/directory dest=/foo/directory 

2 Comments

Do I need to make a new local connection just for changing the local file?
That's how ansible knows to run it locally vs on the remote machines. You can also use local_action as mentioned below. The local connection is good if you have a bunch of things to do locally.
1

Update:
Current Ansible (2.10) does not like - local_action: , instead use delegate_to:

- name: Remove directory 'dir1' file: path: "path/to/dir1" state: absent delegate_to: localhost 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.