Hello everyone I'm using Jenkins to launch a simple Ansible Pipeline (to create . . .

Hamza HEBHOUB:
Hello everyone
I’m using Jenkins to launch a simple Ansible Pipeline (to create a folder on localhost as follow

-
  name: Play1
  hosts: localhost
  become: true
  remote_user: ec2-user
  tasks:
    #- ping:
   - name: Create directory
     file:
       #path: /var/lib/jenkins/workspace/
       path: /home/ec2-user/Newfolder
       state: directory
       group: ec2-user
       owner: ec2-user
       mode: 0700

But when i build the pipeline I got this error message:

TASK [Gathering Facts] *********************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

Have you an idea about this error please ?

Alistair Mackay:
That error usually means that password-less sudo is not configured for the user.
Anyway, you should not need to

become: true

if you are connecting as ec2-user and creating something in ec2-user’s home directory.

Hamza HEBHOUB:
okay thank you for your résponse, I’ll try it

Chandra:
Also pls make sure you have an entry for localhost in your inventory file