FreeKB - Ansible move module
Ansible - move module

Ansible does not have a module that can be used to move files. The copy module can be used to copy files. When you want to move a file from one directory to another directory on a managed node (e.g. target system), the command module can be used, like this. In this example, the command module is used to move the foo.txt fileto the /tmp directory on the managed node.

- name: "move foo.txt to the /tmp directory"
  command: "mv foo.txt /tmp"

 

Or the shell module can be used, like this. In this example, the shell module is used to move the foo.txt file to the /tmp directory on the managed node.

- name: "move foo.txt to the /tmp directory"
  shell: "mv foo.txt /tmp"

 

The following should be produced.

TASK [move foo.txt to the /tmp directory]
changed: [server1.example.com]

 

By default, no stdout is printed. The register module can be used to print output to the console.


non-zero return code

If non-zero return code is being displayed in the output of the play, refer to our article on resolving non-zero return code.

 


Become (root, sudo)

If you do not have permission to move a file, permission denied will be returned. To resolve this, the become module can be used to become root.

 


Arguments

Certain arguments can be used with the shell command. In this example, the chdir (change directory) argument is used to perform the shell command from a particular directory.

- name: ps command
  shell: "ls"
  arg:
    chdir: /root

 


By default, Ansible performs tasks on managed node. Refer to run tasks on the control node if you want to run this module on your control node.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter f0f5f in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |