Using vars_prompt with role name

315 views
Skip to first unread message

Kenneth Koski

unread,
Jul 7, 2016, 5:20:37 PM7/7/16
to Ansible Project
Apologies if this is an easy question, but I have limited experience with Ansible, and I've been unable to find anything about this online. I've got a codebase that looks like this:

# deploy.yml
---
- name: Get app name
  hosts: localhost
  vars_prompt:
    - name: app
      private: no
      prompt: "App name"
  tasks:
    - set_fact:
        app: "{{ app }}"

- name: "Setup {{ app }}"
  hosts: localhost
  roles:
    - role: "app_roles/{{ app }}"

Everything works fine if I call the playbook with 

ansible-playbook -e app=foo -i hosts deploy.yml

However, when I run it with

ansible-playbook -i hosts deploy.yml

it fails with this error, instead of prompting for the value of app

ERROR! 'app' is undefined

It looks like there's two problems here:
  • The play name attribute contains "{{ app }}"
  • The role name contains "{{ app }}"
The play name containing "{{ app }}" is nice but not necessary. The way it's currently architected requires the role to be dynamic, though. That leaves me with two questions:
  • Is there some solution for using vars_prompt in this manner?
  • Is there a better architecture for this?
Reply all
Reply to author
Forward
0 new messages