问题
I am trying to install software on centos 7 using ansible playbook through jenkins.
I am trying to call ansible playbook from jenkins for installing the software.
I am using vars_prompt in ansible playbook to pass some user-defined parameters, when i run the ansible playbook manually, it asks for prompts and runs successfully but when i build using jenkins it doesn't prompt for any inputs.
Pipeline:
node {
ansiblePlaybook(
installation: 'FirstAnsibleTest',
inventory: '/etc/ansible/hosts',
playbook: '/etc/ansible/install.yml',
become: true,
colorized: true,
)
}
install.yml:
- hosts: all
vars_prompt:
- name: "webusername"
prompt: "Enter webusername"
- name: "webpassword"
prompt: "Enter webpassword"
private: yes
tasks:
- import_tasks: /etc/ansible/roles/installe/tasks/main.yml
How can I make jenkins to ask for prompts that can be passed to the ansible playbook?
回答1:
as Jenkins launches the job as non-interactive manner, you need to pass --extra-vars
with the variables and their value when calling the playbook (ex: --extra-vars 'webusername=foo webpassword=bar'
).
This is explained in the documentation.
Prompts for individual
vars_prompt
variables will be skipped for any variable that is already defined through the command line--extra-vars
option, or when running from a non-interactive session (such as cron or Ansible Tower). See Passing Variables On The Command Line in the /Variables/ chapter.
For the password I understand that is not possible to pass it directly but you can for instance use an environment variable.
来源:https://stackoverflow.com/questions/51171764/prompts-in-jenkins