Running under ansible - insufficient permission

i have some problems running specific code using ansible on remote:
background:
ubuntu22 with latest ansible\updates
file /etc/security/limits.conf set with:

* soft core unlimited
* hard core unlimited

running the code directly on the host(without ansible) works

ssh target
sudo su my_user
python3

run code:

import resource
resource.getrlimit(resource.RLIMIT_CORE)
resource.setrlimit(
resource.RLIMIT_CORE,
(resource.RLIM_INFINITY, resource.RLIM_INFINITY)
)

but running the ansible code :

- name: python code
  shell:
    nohup run.py
  args:
  become: yes
  become_method: sudo
  become_user: my_user

does not work- the user don’t have permission to change ulimit

i was able to isolate the problem
ansible login using the command
sudo -i -u my_user /bin/bash
and the code does not working in this scenario,

but normal using sudo su my_user it works

any idea how i can overcome it ?

Shouldn’t that be root in order to have permissions to change the ulimit? What permissions does my_user have?

in general you are right,
but setting the two lines:

* soft core unlimited
* hard core unlimited

in /etc/security/limits.conf give all users (*) to set limits for any size