I'm confused what you want to do when you use a second user. If you want fallback users, I don't know of a simple built in way but have gotten it to work looping user/pass /key combos with gather facts or a shell "sudo -l" command and register. Then loop through your registered var with set_facts and it's possible to set for each host the first successful credential set that worked before continuing the play.
If you want different tasks to be run with different users you can use become and become_user.
Ah I missed your detail about serial usage, but am not sure how you could do that. You could import or include a play with some sort of loop, or maybe registering a var after the final task and setting ansible_ssh_user to that var if it exists prior to the first task?
When i play my playbook, ansible run playbook only on the first line my_host_1 ansible_user=wildfly and not on the second line.
So, same when i use serial: 1 in my playbook, ansible run only the first line.
I think ansible refers only to the host name and does not execute every line of my inventory …?
Do you have any solution please for me community ansible !!!
Ansible doesn't "execute lines of the inventory", it executes plays in
a playbook.
The inventory is to list the hosts you are targeting, so in this case
a single host.
Just have your inventory look like:
my_host_1
And then iterate over your play(s), using a different value for ansible_user.