Creating Soft Links Using Ansible - incorrect task validation for AppServer1 stapp01

Hello,

I would like to clarify some details related to the task
Creating Soft Links Using Ansible

According to the task 4 steps should have done to finish the task:

  1. create src directory for the empty file

  2. create destination directory for the symbolik link

  3. create an empty file with a proper permissions
    in the directory that was created on step [1]

  4. create symbolik link from the file created on step [3] to
    the destination directory created on step [2]

The same operations should be repeated for all application servers (1,2 and 3)

The task finished without any errors.
After ssh I checked the presence of the file and the symlink on the application server1
and found both the file and symlink, however I got the error message:

it seems like you haven’t create symbolic link to ‘/var/www/html’ properly on App Server 1

Please see the output of the /opt/security/ folder on stapp01

[tony@stapp01 ~]$ ls -la /opt/security/
total 8
drwxr-xr-x 2 root root 4096 Jul 15 11:30 .
drwxr-xr-x 1 root root 4096 Jul 15 11:27 …
-rw-r–r-- 1 tony tony 0 Jul 15 11:30 blog.txt

Please see the output of the /var/www/hmtl/ folder on stapp01

[tony@stapp01 ~]$ ls -la /var/www/html/
total 8
drwxr-xr-x 2 root root 4096 Jul 15 11:30 .
drwxr-xr-x 3 root root 4096 Jul 15 11:30 …
lrwxrwxrwx 1 root root 22 Jul 15 11:30 blog.txt → /opt/security/blog.txt

Below is ansible playbook that was used to accomplish this task:


  • hosts: all
    become: yes
    gather_facts: yes
    vars:

    src_path: “/opt/security”
    dst_path: “/var/www/html”
    file1: “blog.txt”
    file2: “story.txt”
    file3: “media.txt”

    tasks:

    • block:

      • name: “Create src directory {{ src_path }}”
        file:
        path: “{{ src_path }}”
        state: directory

      • name: “Create dst directory {{ dst_path }}”
        file:
        path: “{{ dst_path }}”
        state: directory

      • name: “Create empty file {{ src_path }}/{{ file1 }}”
        file:
        path: “{{ src_path }}/{{ file1 }}”
        state: touch
        owner: tony
        group: tony

      • name: “Create symlink {{ src_path }}/{{ file1 }} {{ dst_path }}/{{ file1 }}”
        file:
        src: “{{ src_path }}/{{ file1 }}”
        dest: “{{ dst_path }}/{{ file1 }}”
        state: link

      when: inventory_hostname == “stapp01”

    • block:

      • name: “Create src directory {{ src_path }}”
        file:
        path: “{{ src_path }}”
        state: directory

      • name: “Create dst directory {{ dst_path }}”
        file:
        path: “{{ dst_path }}”
        state: directory

      • name: “Create empty file {{ src_path }}/{{ file2 }}”
        file:
        path: “{{ src_path }}/{{ file2 }}”
        state: touch
        owner: steve
        group: steve

      • name: “Create symlink {{ src_path }}/{{ file2 }} {{ dst_path }}/{{ file2 }}”
        file:
        src: “{{ src_path }}/{{ file2 }}”
        dest: “{{ dst_path }}/{{ file2 }}”
        state: link

      when: inventory_hostname == “stapp02”

    • block:

      • name: “Create src directory {{ src_path }}”
        file:
        path: “{{ src_path }}”
        state: directory

      • name: “Create dst directory {{ dst_path }}”
        file:
        path: “{{ dst_path }}”
        state: directory

      • name: “Create empty file {{ src_path }}/{{ file3 }}”
        file:
        path: “{{ src_path }}/{{ file3 }}”
        state: touch
        owner: banner
        group: banner

      • name: “Create symlink {{ src_path }}/{{ file3 }} {{ dst_path }}/{{ file3 }}”
        file:
        src: “{{ src_path }}/{{ file3 }}”
        dest: “{{ dst_path }}/{{ file3 }}”
        state: link
        when: inventory_hostname == “stapp03”

Could you please advise on what might be wrong here?
Could it be that validation system for the AppServer 1 does not work as expected?

Thank you.

Best regards,
Alex

My bad.

It seems that the error was because I misunderstood the task:

The requirement in the task was to create a link from src directory to dst directory:
Create a symbolic link of source path /opt/itadmin to destination /var/www/html .

and not from the file to the symlink in the /var/www/html/*.txt