Good afternoon, could you help me?
I need to copy a file to a remote host with a .bin extension and run it with administrator rights. What kind of playbook is needed (the one that displays the GPT chat does not work).
Remote host Ubuntu 22.04
Assumptions
I’m going to assume the following items for my example below
- You have all the prerequisite items setup to make the playbook work
(Inventory, host_vars, etc.) - SSH To your remote system works
- The admin user on the remote system is root
- Your bin file is stored locally on your system at /tmp/my_file.bin
Items to Learn
- Ansible’s copy module.
- Ansible’s become capabilities
- Ansible’s expect module, if your executable is going to require interaction to prompts in order to install properly.
Example Playbook
If your executable requires prompt interaction, replace ansible.builtin.copy
with ansible.builtin.expect
and use the link above to learn how to use it.
---
- name: Copy my_file.bin to Remote Server:/tmp/my_remote_file.bin
hosts: all
become: yes
become_user: root
become_method: sudo
tasks:
- name: Copy the file
ansible.builtin.copy:
src: /tmp/my_file.bin
dest: /tmp/my_remote_file.bin
- name: Execute the file
ansible.builtin.shell: "sh /tmp/my_remote_file.bin"
3 Likes