Unable to execute ansible playbook

Hi all,

I got the following error, while trying to execute ansible playbook:

TASK [Gathering Facts] ************************************************************************************************************************************************************************************

fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo /var/tmp"&& mkdir "echo /var/tmp/ansible-tmp-1657172514.8192306-2106-9375282374437" && echo ansible-tmp-1657172514.8192306-2106-9375282374437="echo /var/tmp/ansible-tmp-1657172514.8192306-2106-9375282374437" ), exited with result 142, stdout output: Please login as the user "cloud-user" rather than the user "root".\n\n”, “unreachable”: true}

While executing the command provide -k option and provide the root password or
Authenticate your localhost.

This might give you a clue - stdout output: Please login as the user "cloud-user" rather than the user "root".\n\n"

But My playbook is available with root user.

I am able to log in with cloud-user and then with sudo privileges as root, I have implemented a play book. So that I can execute playbook with root privileges.

the same issue happens even I have provided with -K argument:

SSH password:

PLAY [default] ********************************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************************

fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo /var/tmp"&& mkdir "echo /var/tmp/ansible-tmp-1657181023.834322-2338-216353050127500" && echo ansible-tmp-1657181023.834322-2338-216353050127500="echo /var/tmp/ansible-tmp-1657181023.834322-2338-216353050127500" ), exited with result 142, stdout output: Please login as the user "cloud-user" rather than the user "root".\n\n”, “unreachable”: true}

PLAY RECAP ************************************************************************************************************************************************************************************************

localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

the same issue happens even I have provided with -K argument:

You need to login as the cloud-user and use privilege escalation (https://docs.ansible.com/ansible/latest/user_guide/become.html) to execute the tasks as root user.

ansible_user: cloud-user
become: yes
become_method: sudo

Regards
          Racke

  • hosts: default

ansible_user: cloud-user

become: yes

become_method: sudo

gather_facts: true

Error:

ERROR! ‘ansible_user’ is not a valid attribute for a Play

The error appears to be in ‘/root/modsec-compile.yml’: line 2, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- hosts: default

ansible_user: cloud-user

become: yes

become_method: sudo

gather_facts: true

Error:

ERROR! 'ansible_user' is not a valid attribute for a Play

Hello,

the ansible_user needs to be set in the inventory.

Regards
         Racke

cat hosts

[default]

localhost

ansible_user=cloud-user

odsec-test ~]# vi hosts

[root@modsec-test ~]# ansible-playbook -i ./hosts modsec-compile.yml --private-key nonprod

PLAY [default] ********************************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************************

fatal: [ansible_user=cloud-user]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname ansible_user=cloud-user: Name or service not known”, “unreachable”: true}

fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo Please login as the user \"cloud-user\" rather than the user \"root\"./.ansible/tmp"&& mkdir "echo Please login as the user \"cloud-user\" rather than the user \"root\"./.ansible/tmp/ansible-tmp-1657190959.6394126-3019-148910985051576" && echo ansible-tmp-1657190959.6394126-3019-148910985051576="echo Please login as the user \"cloud-user\" rather than the user \"root\"./.ansible/tmp/ansible-tmp-1657190959.6394126-3019-148910985051576" ), exited with result 142, stdout output: Please login as the user "cloud-user" rather than the user "root".\n\n”, “unreachable”: true}

PLAY RECAP ************************************************************************************************************************************************************************************************

ansible_user=cloud-user : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

cat hosts

[default]

localhost

ansible_user=cloud-user

[default]
localhost ansible_user=cloud-user

Regards
          Racke

It works. Thanks Racke.