Ansible find module not accepting fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (find) module: become Supported parameters include: age, age_stamp, contains, depth, excludes, file_type, follow, get_checksum, hid

I want to access a directory as sudo user of Linux when i gave

Below is the code for the same which i tried;

  • name: Ansible delete files older than 1 minutes example
    find:
    paths: ‘{{diskclrpath}}’
    age: ‘{{fileage}}’
    patterns: ‘{{file_ext}}’

size: ‘{{file_size}}’

recurse: yes
become: true

become_method: su

register: files_to_delete

  • debug:
    msg: “files in the path are: ‘{{files_to_delete}}’”

  • name: Ansible remove files older than a date example
    file:
    path: “{{ item.path }}”
    state: absent
    become: yes
    with_items: “{{ files_to_delete.files }}”
    loop_control:
    label: “{{ item.path }}”
    when: ((diskspc_util >= ‘{{diskuseper}}’) and ( ‘rwx’ not in permissionchk))

getting below Error for it.

fatal: [127.0.0.1]: FAILED! => {“changed”: false, “msg”: “Unsupported parameters for (find) module: become Supported parameters include: age, age_stamp, contains, depth, excludes, file_type, follow, get_checksum, hidden, paths, patterns, recurse, size, use_regex”}

Please help me on this.

I want to access a directory as sudo user of Linux when i gave

Below is the code for the same which i tried;

 \- name: Ansible delete files older than 1  minutes  example
   find:
     paths: '\{\{diskclrpath\}\}'
     age: '\{\{fileage\}\}'
     patterns: '\{\{file\_ext\}\}'

# size: '{{file_size}}'
recurse: yes
become: true
# become_method: su
register: files_to_delete
- debug:
msg: "files in the path are: '{{files_to_delete}}'"

 \- name: Ansible remove files older than a date example
   file:
     path: "\{\{ item\.path \}\}"
     state: absent
     become: yes
   with\_items: "\{\{ files\_to\_delete\.files \}\}"
   loop\_control:
      label: "\{\{ item\.path \}\}"
   when: \(\(diskspc\_util >= '\{\{diskuseper\}\}'\) and \( 'rwx' not in permissionchk\)\)

getting below Error for it.

fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (find) module: become Supported
parameters include: age, age_stamp, contains, depth, excludes, file_type, follow, get_checksum, hidden, paths, patterns,
recurse, size, use_regex"}

Please help me on this.

Well, the error message gives the clue away. "become" is as task parameter and not a parameter of the find module.
So you need to fix the indentation.

Regards
           Racke

Become is a task keyword. In your playbook you are using it as if it were a parameter of the “find” module. Move it up under the “name” line and indent it to the same level as the module name:

  • name: Ansible delete files older than 1 minutes example

become: true
become_method: su

find:
paths: ‘{{diskclrpath}}’
age: ‘{{fileage}}’
patterns: ‘{{file_ext}}’

size: ‘{{file_size}}’

recurse: yes
register: files_to_delete

  • debug:
    msg: “files in the path are: ‘{{files_to_delete}}’”

See https://docs.ansible.com/ansible/latest/user_guide/become.html for more details.