Copy Files and Append Text
to Remote Hosts
● To copy the files from control node to remote hosts
● Attributes
○ src: Source file to be copied
○ dest: Destination directory on the remote clients
○ owner: Sets the file owner to root
○ group: Sets the file group to root
○ mode: Sets the file permissions
● Link: copy module — Ansible Documentation
Copy Module
Copy files to Remote Hosts
● Execute the playbook on control node
Command: ansible-playbook <file-name> . yml
● Verify if the text file is copied to the directory of the remote host
Command: ls /tmp | grep sample.txt
● Module to insert, update, or remove a block of text in a file in Ansible
● Attributes
○ path: specifies the path where the file should be created
○ state: create a file
○ block: text which is added to the file
● Link: blockinfile — Ansible Documentation
Blockinfile Module
Append text to the text file
● Execute the playbook on control node
Command: ansible-playbook <file-name> . yml
● Verify if the text is appended to the file on remote host
Command: ansible-playbook <file-name> . yml
Appended text

Copy Files and Append Text to Remote Host - RHCE.pdf

  • 1.
    Copy Files andAppend Text to Remote Hosts
  • 2.
    ● To copythe files from control node to remote hosts ● Attributes ○ src: Source file to be copied ○ dest: Destination directory on the remote clients ○ owner: Sets the file owner to root ○ group: Sets the file group to root ○ mode: Sets the file permissions ● Link: copy module — Ansible Documentation Copy Module
  • 4.
    Copy files toRemote Hosts
  • 5.
    ● Execute theplaybook on control node Command: ansible-playbook <file-name> . yml
  • 6.
    ● Verify ifthe text file is copied to the directory of the remote host Command: ls /tmp | grep sample.txt
  • 7.
    ● Module toinsert, update, or remove a block of text in a file in Ansible ● Attributes ○ path: specifies the path where the file should be created ○ state: create a file ○ block: text which is added to the file ● Link: blockinfile — Ansible Documentation Blockinfile Module
  • 8.
    Append text tothe text file
  • 9.
    ● Execute theplaybook on control node Command: ansible-playbook <file-name> . yml
  • 10.
    ● Verify ifthe text is appended to the file on remote host Command: ansible-playbook <file-name> . yml Appended text