How to move rename a file using an Ansible task on a remote system

0 votes

Hi Guys,

I have some files in the remote system. I want to move those files when a particular task will run. How can I control that?

Sep 17, 2020 in Ansible by akhtar
• 38,210 points

1 answer to this question.

0 votes


You can use the command module to move your files. But before running that task, you should check if the file is present or not as shown below.

- name: state check
  stat: path=/path/to/foo
  register: foo_stat
- name: Move foo to bar
  command: mv /path/to/foo /path/to/bar
  when: foo_stat.stat.exists
answered Sep 17, 2020 by MD
• 95,300 points

Related Questions In Ansible

0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,300 points
0 votes
1 answer

How to create a new encrpted file using Ansible Vault?

If you are creating a new file ...READ MORE

answered Jan 29, 2019 in Ansible by Kyraa
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
0 votes
1 answer

How to start httpd service in a remote system using Ansible?

Hi@akhtar, Ansible has a module named service. This ...READ MORE

answered Jul 30, 2020 in Ansible by MD
• 95,300 points