4.Copy Data to App Servers using Ansible
Thu Kha Kyawe

Thu Kha Kyawe @thukhakyawe_cloud

About: Certified in AWS, HashiCorp, and GitHub, I bring both strategic vision and technical expertise to design solutions that support business growth, optimize costs, and enhance operational efficiency.

Joined:
Nov 7, 2025

4.Copy Data to App Servers using Ansible

Publish Date: Dec 10 '25
0 0

Lab Information

The Nautilus DevOps team needs to copy data from the jump host to all application servers in Stratos DC using Ansible. Execute the task with the following details:

a. Create an inventory file /home/thor/ansible/inventory on jump_host and add all application servers as managed nodes.

b. Create a playbook /home/thor/ansible/playbook.yml on the jump host to copy the /usr/src/itadmin/index.html file to all application servers, placing it at /opt/itadmin.

Note: Validation will run the playbook using the command ansible-playbook -i inventory playbook.yml. Ensure the playbook functions properly without any extra arguments.

Lab Instructions

Step 1: Create the Inventory File

First, let's create the inventory file with all application servers:
bash

Create the directory if it doesn't exist

mkdir -p /home/thor/ansible

Create the inventory file

cat > /home/thor/ansible/inventory << EOF
[app_servers]
stapp01 ansible_host=172.16.238.10 ansible_user=tony ansible_ssh_pass=Ir0nM@n
stapp02 ansible_host=172.16.238.11 ansible_user=steve ansible_ssh_pass=Am3ric@
stapp03 ansible_host=172.16.238.12 ansible_user=banner ansible_ssh_pass=BigGr33n
EOF
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Playbook

Now, let's create the playbook that will copy the file:

cat > /home/thor/ansible/playbook.yml << 'EOF'
---
- name: Copy index.html to application servers
  hosts: app_servers
  become: yes
  become_method: sudo
  tasks:
    - name: Ensure destination directory exists
      file:
        path: /opt/itadmin
        state: directory
        owner: root
        group: root
        mode: '0755'

    - name: Copy index.html file to application servers
      copy:
        src: /usr/src/itadmin/index.html
        dest: /opt/itadmin/index.html
        owner: root
        group: root
        mode: '0644'
EOF
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the Files

Check that both files were created correctly:

# Check inventory file
cat /home/thor/ansible/inventory

# Check playbook file
cat /home/thor/ansible/playbook.yml
Enter fullscreen mode Exit fullscreen mode

Step 4: Test the Playbook

Run the playbook to test it:

cd /home/thor/ansible
ansible-playbook -i inventory playbook.yml
Enter fullscreen mode Exit fullscreen mode

Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Comments 0 total

    Add comment