FreeKB - rename module
Ansible - rename module

Ansible does not have a module that can be used to rename files. The copy module can be used to copy files. When you want to rename a file 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 rename foo.txt to bar.txt.

- name: "rename foo.txt to bar.txt"
  command: "mv foo.txt bar.txt"

 

Or the shell module can be used, like this. In this example, the shell module is used to rename foo.txt to bar.txt.

- name: "rename foo.txt to bar.txt"
  shell: "mv foo.txt bar.txt"

 

The following should be produced.

TASK [rename foo.txt to bar.txt]
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.

 


Sudo / Become

If you want to perform a task on target server(s) that requires the use of sudo, refer to our article on using the become module.

 


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

 


connection module / delegate_to module

By default, Ansible performs tasks on managed node. The connection module or delegate_to module can be used to invoke the command module on the control node (that's the Ansible server). 



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 2d705 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   |