4-Deploy Files To Managed Hosts
4-Deploy Files To Managed Hosts
(RHCE - EX294)
Deploy Files to Managed Hosts
Copy Files to Remote Clients
# echo somestuff > /home/iafzal/some.cfg
# vim copy.yml
---
- name: Copy file from local to remote clients Description of the playbook
hosts: all Run it on all hosts
tasks: Run the following task(s)
- name: Copying file Description of the task
become: true Transfer as a current user
copy: Run copy module
src: /home/iafzal/some.cfg
dest: /tmp
Source of the file
owner: iafzal
group: iafzal
Destination of the file
mode: 0644
Change ownership and file permissions
# Login to ControlNode
# vim filepermission.yml
---
- name: Change file permissions
hosts: all
tasks:
- name: Files Permissions
file:
path: /home/iafzal/linux2 File location
mode: a+w Permissions
---
- name: File status module
hosts: localhost
tasks:
- name: Check file status and attributes
stat: stat module
path: /etc/hosts File path/location
register: fs Register or output to fs container
- name: Show result
debug: debug module to print
msg: File attributes {{ fs }} Print what is inside of fs container
---
- name: Create a file and add text
hosts: localhost
tasks:
- name: Create a new file
file: file module
path: /tmp/george File path/location
state: touch Create a file
- name: Add text to the file
blockinfile: blockinfile module
path: /tmp/george
block: George is one of the main Add text to the file
character of Seinfeld show and he is Jerry’s
best friend