include_vars and include before hosts play i need to implement

340 views
Skip to first unread message

pinky

unread,
Oct 1, 2016, 9:24:06 PM10/1/16
to Ansible Project
Hi,

    I have created my own custom library , i added my custom library in the common folder of my repository.In that i need to pass variables dyanamically .Its a confidential password,so iam using "vault" in ansible.

  In that my requirement is how to pass include_vars in the tasks\main.yml before hosts.

e.g: mytasks.yml
  - include_vars: sample_vault.yml
  - include: sample_tasks.yml
  - hosts: localhost
    tasks:
      name: "free task"
      command: ls -a

my directory structure like this:

  myfolder
    - common 
        -library   
           -my file.py
        - sample_tasks.yml

    - mytasks
        -mytasks.yml(my main master playbook file)
        -sample_vault.yml  (note:i create this using vault for confidential purpose)
        - roles
           -myrole


Here i need to run sample_tasks file using a variables passed in sample_vault.yml file before i execute the hosts tasks using ansible.If i use extra variable means password is visible so i dont need that.

When i use include_vars in my tasks/main.yml file, it shows the following error:

"ERROR! 'include_vars' is not a valid attribute for a Play"




Thanks

Brian Coca

unread,
Oct 3, 2016, 12:26:37 AM10/3/16
to ansible...@googlegroups.com
No tasks can live outside of a play, except for `include` and this exception only applies when it is including plays.

include_vars must be inside a play.

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages