0

I have the following playbook and struggling to understand how to pass it the application_name variable:

---

- name: Initial configuration for a {{ application_name }} server
  hosts: all
  vars:
    - update_apt_cache: yes
  vars_files:
    - roles/base/defaults/main.yml

  tasks:
    - debug: msg="reading from group {{ groups }} and application name {{ application_name }}"

The issue is that the first application_name (in the name parameter) never works, though the second instance (defined in the task) works fine. How can I get the first instance to work as well? I've tried both defining the variable in the inventory...

[mygroup:vars]
application_name=my_application_name

...and in group_vars (./group_vars/mygroup/vars.yml)...

application_name: my_application_name

...but both of these do not fill the name parameter - only the {{ application_name }} found in the tasks section of the playbook.

Is there a way to fill in the first application_name variable?

YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • 1
    Possible duplicate of [Ansible playbook condition fails when variable has a default value](https://stackoverflow.com/questions/40863809/ansible-playbook-condition-fails-when-variable-has-a-default-value) – Konstantin Suvorov Jul 13 '17 at 15:28
  • Playbook is a file, its name is stored in the filesystem, and it doesn't have any parameters. – techraf Jul 14 '17 at 00:41

2 Answers2

2

I'm not sure if you can use the playbook name in the manner you want to. group_vars aren't loaded until after the playbook name is displayed. To fill in the application_name in the playbook name you would either have to define it in the playbook vars section

- name: Initial configuration for a {{ application_name }} server
  hosts: all
  vars:
    - update_apt_cache: yes
    - application_name: foo

or with extra-vars on the command line

ansible-playbook -e "application_name=foo" your_playbook.yml
kfreezy
  • 1,499
  • 12
  • 16
0

Just a wild guess, did you tried to quote variable?

- name: 'Initial configuration for a {{ application_name }} server'