Ansible fact gathering task failed

Hi @Inderpreet @player001 @kodekloud-support3

Ansible Facts gathering task was completed with the requirement as mentioned in the task but still the task failed.

Task Failed

  • ‘/root/facts.txt’ file doesn’t contain correct data on App Server 1

Can you please explain what did I missed?

Thank you in advance!

Hello, kleansoul
I think you have to collect ipv4 addr(172.16.238.10) instead of default-ipv4-address.

@player001 Thanks for your reply.

Unfortunately it wasnt mentioned anywhere in the question.
The task didn’t said anything like that.

That was my assumption after looked images result. There is no mean of default-ipv4-address. Basically we do gather_facts to get a information of system info. I haven’t seen task description so i have no clue to say more.

Hi ,

Did anyone else got the same task? Any response.

Hi @kleansoul , @player001, @Lakshmi , @kodekloud-support3 , @Inderpreet
for this task do we need to use {{ ansible_facts.default_ipv4.address }} in the block attribute of blockinfile module since there is no such variable/fact that is called “default-ipv4-address” ,ie,
like

block: "Ansible managed node IP is {{ ansible_facts.default_ipv4.address }}"

and is that the only task that needs to be present in index.yml file , ie, is the httpd installation to be done manually without using ansible ?

1 Like

The task question seems to lack some further information. That’s why I too wanted to clarify it but havn’t received any reply yet. Seems like only you and I have received this task soo far.

Awaiting for a response from KKE team to clarify and recheck my task.

Yeah , ip address variable is confusing . But @kleansoul for the httpd setup and the copy of facts.txt to index.html , did you do those steps without using ansible ?

I did all using ansible playbook. :slight_smile:

You can understand that from the output screenshot that I pasted in my initial post.

Awaiting for KKE Team @Inderpreet @kodekloud-support3 to check and update.

Hello @kleansoul,

I’ve pass that task too and it’s OK for me, I did it like @antonysavio1111 :

   blockinfile:
       dest: /root/facts.txt
       block: |
         Ansible managed node IP is {{ ansible_default_ipv4.address }}
2 Likes

Hi @Goldenor,

For me question was not completely clear. I understood that if there is nothing mentioned in the task to use the specific variable then better not use it , so thus I didn’t and therefore failed and easy one! :frowning:

I wish the task was framed correctly so at least it would say something about using a variable.

Thanks for your reply.

Yeah I agree with u :slight_smile:

Hi guys @Goldenor @kleansoul @antonysavio1111 @player001,

I have failed this task though I was able to complete is successfully as per the instructions. I have added the block "Ansible managed node IP is " as it is. Yes, the “” does not do the job but it is what was given from the task instructions :thinking:.

Guys @Inderpreet @KodeKloud @kodekloud-support3, how do you treat this one.

Here is the output of what i did

Verifying the facts.txt and index.html file on the application servers


Checking the httpd service an all application servers
stapp01:

stapp02

stapp03

index.yml playbook


Validation:

Am I supposed to create the root user? because it does not exist!!!

Cheers,
Salim

Hi @Salim , the facts.txt should be located at /root dir and not at / dir . Your validation screenshot shows that the file is located at / dir which is also indicated in the task failure message (/root/facts.txt does not exist) and you should also use an ansible variable when using blockinfile module like so

"Ansible managed node IP is {{ ansible_facts.default_ipv4.address }}"

since as per you screenshot you are using the sentence given in the task

Ansible managed node IP is <default-ipv4-address>

which is incorrect

1 Like

Thanks @antonysavio1111.

However you are missing the point here. If you check my post I agree with you that the “<default-ipv4-address” is incorrect and but it what was given from the task instructions. And yes I am aware that I put the facts.txt file in the wrong location. It would be better if the task removed the “<default-ipv4-address” or replace it which the correct entry. Suppose I have put the facts.txt in the /root/ but I have used the"<default-ipv4-address" , would this task marked failed or success?

Where is it given “” in the task instructions ?

There is also a trick on how you can speed up your plays with filtering facts gathering in ansible. If you need only default_ipv4.address in the play you can do following:

- hosts: someinventorygroup
  gather_facts: no
  pre_tasks:
   - setup:
       filter: ansible_default_ipv4
  roles: # or tasks:

This trick is working with gathering = explicit in /etc/ansible/ansible.cfg

1 Like

Hi @Salim facts.txt isn’t in the right place u fail the task,
another point, right there is nothing in task instructions that tells you to use the ansible variable for default_ipv4, but in your case that’s not the cause :slight_smile: , Good luck for the rest

Sorry for this incontinence guys, this task is marked Pending for all whoever failed it due to missing information or confusions.

Could you let us know what issues/confusions you guys have with this task ?

Thank you @Inderpreet for your update.

I would request you to reframe the question so we can understand it clearly that the task is asking to use the ansible variable.

The below line alone was little misleading for few of us.

Ansible managed node IP is <default-ipv4-address>