100 days of devops Day 91: Ansible Lineinfile Module

Hi,

I’m working on the Ansible httpd challenge and the playbook completes successfully on all three app servers:

stapp01 : ok=7 changed=6 unreachable=0 failed=0
stapp02 : ok=7 changed=6 unreachable=0 failed=0
stapp03 : ok=7 changed=6 unreachable=0 failed=0

My playbook contains:

---
- name: Setup Apache web server
  hosts: all
  become: true

  tasks:
    - name: Install httpd
      ansible.builtin.package:
        name: httpd
        state: present

    - name: Ensure httpd is running
      ansible.builtin.service:
        name: httpd
        state: started
        enabled: true

    - name: Create index.html
      ansible.builtin.copy:
        dest: /var/www/html/index.html
        content: "This is a Nautilus sample file, created using Ansible!\n"

    - name: Add welcome message at the top
      ansible.builtin.lineinfile:
        path: /var/www/html/index.html
        line: "Welcome to xFusionCorp Industries!"
        insertbefore: BOF

    - name: Set ownership of index.html
      ansible.builtin.file:
        path: /var/www/html/index.html
        owner: apache
        group: apache

    - name: Set permissions on index.html
      ansible.builtin.file:
        path: /var/www/html/index.html
        mode: '0755'

However, the challenge validator reports:

file '/var/www/html/index.html' having incorrect permissions on stapp01

I checked the file directly on stapp01:

$ stat -c '%a %U %G' /var/www/html/index.html
755 apache apache

The file contents are also correct:

$ cat /var/www/html/index.html
Welcome to xFusionCorp Industries!
This is a Nautilus sample file, created using Ansible!

So I’m confused why the validator reports incorrect permissions.

Is there something I’m missing about how the validator checks the permissions, or is there another detail I should verify?

The file permissions for index.html I got was 0655 and following worked for me:

  - name: file permissions
    file:
      path: /var/www/html/index.html
      owner: apache
      group: apache
      mode: '0655' 

Oke, then there is a o problem in the challenge description

The /var/www/html/index.html file's permissions should be 0755 on all app servers.

Probably, the file permission requirement is dynamically set for each task instance.
Could you please retry this again?

My version just merges two tasks from your approach into one. Set ownership and permissions.

I will try that
Maybe that is the trick

Thanks
Finally this task is also solved