TL; DR: Is it possible to connect two pieces with one single play command, in which one playbook is the auth password and the other is the key auth? (see last section for real world purposes).
Setup:
I have two plays, the second of which include first.
PlaybookA.yml
--- - name: PlaybookA # requires password authentication hosts: sub.domain.ext remote_user: root roles: - { role: role1, sudo: yes } ...
PlaybookB.yml
--- - name: Run PlaybookA include: PlaybookA.yml - name: PlaybookB # requires ssh-key authentication hosts: sub.domain.ext remote_user: ansible roles: - { role: role2, sudo: yes } ...
Requirements:
- Run only one command.
- Use auth password for PlaybookA.
- Use ssh-key auth for PlaybookB.
Question 1:
Is it possible in Ansible (version 1.9.4 or lower) to run one ansible-playbook command that will successfully launch PlaybookB using ssh key authentication, but when PlaybookB includes PlaybookA, start PlaybookA using password authentication?
Question 2:
If this is not possible with Ansible 1.9.4 or lower, is it possible with 2.0.0 +?
Notes:
- Ansible provides
--ask-pass (or -k ) as a command line switch that allows password authentication. - Ansible provides
ask_pass as a variable, but it seems that it can only be set in ansible.cfg (I could not set this as a playbook variable for the desired effect). - Attempting to set
ask_pass as an instruction in the ask_pass results in the following: ERROR: ask_pass is not a legal parameter of an Ansible Play . If this option is legal, it will provide you with a way to instruct at the level of each book which authentication method to use.
Purpose / Real World:
I am trying to create a configuration management workflow using Ansible that will be simple enough so that others at work can learn / adapt to it (and hopefully using Ansible in general for CM and orchestration).
For any new machine (VM or physical) to be built, I intend to immediately launch two boot books at once. PlaybookA (as shown above) is responsible for logging in with the correct user by default (this usually depends on the infrastructure [aws, vsphere, none, etc.]). Come in, very limited work:
- Create a standardized user to be able to run it (and set its ssh key).
- Remove any non-root users that may exist (vm infrastructure artifacts, etc.).
- Disable root access.
- Disable password authentication (only ssh key from this point).
Depending on the vm infrastructure (or lack thereof), the default user or default authentication method may be different. Regarding the goal of adopting Ansible, I am trying to make things extremely simple for fellow colleagues, so I would like to automate as much of this flow control as possible.
After PlaybookA has blocked vm and installed a standardized user, PlaybookB uses this standardized user to perform all other operations necessary to bring our vm to the necessary baseline of tools and utilities, etc.
Any advice, tips, suggestions are welcome.