Is it possible to use ask-pass option in a playbook just for the first play?

Hello community,

I’ve written a playbook which looks like this:

main.yml:

  • hosts: $hosts

user: root

roles: - add_ansible_user

  • hosts: $hosts

user: ansible

sudo: yes

roles: - do_stuff2

I run this playbook like this:

ansible-playbook -e hosts=foobar -k

First part is working well. Second part is failing, because ansible still uses the password I set with -k and not the it’s ssh-key.

Is there a possibility to use -k option just for the first part of the playbook?

Any ideas?

Thanx in advance

–ask-pass currently applies to all plays.

I think you would want to split it in two plays in this case.

You could keep on using the password for the rest of the play I would think.