As I remember, in this task you must add line on the top of the file.
And lab itself add extra line in file, just for make in harder.
So try to use this:
---
- name: Service httpd
hosts: all
become: yes
tasks:
- name: Install the latest version of httpd
ansible.builtin.yum:
name: httpd
state: present
- name: Start httpd
ansible.builtin.service:
name: httpd
state: started
enabled: yes
- name: Create the index.html file
ansible.builtin.copy:
dest: /var/www/html/index.html
content: |
This is a Nautilus sample file, created using Ansible!
- name: Add a line to a file
ansible.builtin.lineinfile:
path: /var/www/html/index.html
line: Welcome to xFusionCorp Industries!
insertbefore: BOF
mode: '0644'
owner: 'apache'
group: 'apache'
I checked your playbook, and the playbook was putting the “Welcome to …” message at the bottom in the index.html page. As per the task description, this should be at the top.