I am going to replace a file on the destination end. I will replace the index.html on a Ubuntu apache2 which is the front end webpage with my own one.
I will create the file on the ansible control node and create a playbook to copy the file.
sudo mkdir webfiles
cd webfiles
sudo nano default-site.html
<html>
<title> ansible website </title>
<body><p>Ansible is a great automation tool</p></body>
</html>
cd /etc/ansible/playbooks
sudo nano copyfiles.yml
I will install apache2 first then copy the file
---
- hosts: webservers
become: true
tasks:
- name: install apache2 on Ubuntu
tags: webserver
apt:
name: apache2
state: latest
when: ansible_distribution == 'Ubuntu'
- hosts: webservers
become: true
tasks:
- name: copy file to webserver
tags: webserver
copy:
src: /etc/ansible/webfiles/default-site.html
dest: /var/www/html/index.html
owner: root
group: root
mode: 0644
when: ansible_distribution == 'Ubuntu'
file gets renamed when copied to index.html and mode is linux permissions
ansible-playbook --ask-become-pass copyfiles.yml
screenshots below




