---
- name: Lineinfile task
hosts: all
become: yes
tasks:
- name: Install the latest version of Apache
yum:
name: httpd
state: latest
- name: start and enable httpd
ansible.builtin.service:
name: httpd
state: started
enabled: true
- name: Add a line to a file if the file does not exist, without passing regexp
ansible.builtin.lineinfile:
path: /var/www/html/index.html
line: This is a Nautilus sample file, created using Ansible!
create: true
owner: apache
group: apache
mode: '0777'
- name: Add one more line
ansible.builtin.lineinfile:
path: /var/www/html/index.html
line: Welcome to xFusionCorp Industries!
insertbefore: 'BOF'
Failure msg: - incorrect content found in ‘/var/www/html/index.html’ file on stapp01
In the index.html, I see the file contains 3 lines, with Welcome msg at the top of the file.
What I’m doing wrong here?