ansible --version
ansible 2.4.0.0
molecule --version
molecule, version 2.3.1
our git repo is configured as below
kerberos.yml
group_vars/all.yml
dev/group_vars/all.yml
qa/group_vars/all.yml
prod/group_vars/all.yml
roles/
hive
hbase
ruby
molecule/default/molecule.yml
webserver.yml
mysql.yml
i'm looking if its possible to override variables like first look in dev/group_vars , then qa/group_vars ..so on.
currently i'm declaring all variables required in molecule.yml and am able to run it good but i want to avoid this type of declaration.
Please suggest if any improvements can be incorporated
Hi @r0ckyte this is not possible. Ansible loads group vars based on the group the system is in, and Molecule will only symlink out to a single group_vars directory.
You can try moving all of your groups under a single directory, such as:
group_vars/dev/all.yml
group_vars/qa/all.yml
group_vars/prod/all.yml
Then placing your systems into groups, but I'm not so sure how that would work. Also, you really want to test these things in isolation a bit more. You don't want items from dev bleeding over into your qa tests.
platforms:
- name: etcd-01
image: solita/ubuntu-systemd:latest
privileged: True
command: /sbin/init
groups:
- dev
- qa
- prod
I suggest a scenario per scenario you wish to test.
@retr0h - Thanks for the suggestion.
lastly, few of my roles has include_vars as first statement and molecule is searching specified vars file at .molecule/group_vars not at path specified. can i override include_vars via molecule.yml ?
This is a great framework to test, i'm learning slowly and enjoying it. Thanks a ton !!
@retr0h - Thanks for the suggestion.
lastly, few of my roles has include_vars as first statement and molecule is searching specified vars file at .molecule/group_vars not at path specified. can i override include_vars via molecule.yml ?
That I am not sure of. I believe Ansible is using that directory b/c Ansible by default uses the directory specified by -i. Molecule has to maintain host inventory so it uses -i molecule/$scenario_name/.molecule/ansible_inventory.yml. I'm not entirely sure how one would change that behavior.
Looks like you could get fancy with include_vars and pwd.
tasks:
- include_vars:
file: "{{ lookup('env','PWD') }}/foo.yml"
The above will load foo.yml from the current directory. You can modify to suit your needs. I also suggest looking into other ansible built in vars such as playbook_dir.
@r0ckyte thank you for the issue. Closing out.
Most helpful comment
Looks like you could get fancy with
include_varsand pwd.The above will load foo.yml from the current directory. You can modify to suit your needs. I also suggest looking into other ansible built in vars such as
playbook_dir.