# \`defaults/main.yaml\` is not being considering in \`ansible-test integration\`

**URL:** <https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119>\
**Category:** Get Help\
**Tags:** ansible-test, collections\
**Created:** [January 2, 2024, 3:22am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119 "2024-01-02T03:22:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 3:22am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/1 "2024-01-02T03:22:55Z")

</div>

**`defaults/main.yaml` is not being considering in `ansible-test integration`**

I am writing integration tests for `netscaler.adc` collection.

my tests directory structure is as below.

```bash
❯ tree tests/integration
tests/integration
├── integration_config.yml
├── integration_config.yml.template
└── targets
    └── nsip
        ├── defaults
        │ └── main.yaml
        └── tasks
            └── main.yaml

4 directories, 4 files

```

### defaults/main.yaml

```yaml
❯ cat tests/integration/targets/nsip/defaults/main.yaml
ns_common_args: &ns_common_args
  nsip: "{{ nsip }}"
  nitro_user: "{{ nitro_user }}"
  nitro_pass: "{{ nitro_pass }}"
  nitro_protocol: "{{ nitro_protocol }}"
  validate_certs: "{{ validate_certs }}"
  save_config: "{{ save_config }}"

```

### tasks/main.yaml

```yaml
- name: Add NSIP | --check
  delegate_to: localhost
  register: result
  check_mode: true
  netscaler.adc.nsip:
    <<: *nsip_defaults
    state: present
    ipaddress: 1.1.1.1
    netmask: 255.255.255.0
    type: VIP

- name: Assert on add | --check
  ansible.builtin.assert:
    that:
      - "result.failed==false"
      - "result.changed==true"

- name: Add NSIP
  delegate_to: localhost
  register: result
  netscaler.adc.nsip:
    <<: *nsip_defaults
    state: present
    ipaddress: 1.1.1.1
    netmask: 255.255.255.0
    type: VIP

```

### command I am running

```bash
> ansible-test integration

```

### Error I am getting

```bash
> ansible-test integration 
Running nsip integration test role
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  found undefined alias

The error appears to be in '/Users/sumanthlingappa/.ansible/collections/ansible_collections/netscaler/adc/tests/output/.tmp/integration/nsip-n09cxv3o-ÅÑŚÌβŁÈ/tests/integration/targets/nsip/tasks/main.yaml': line 6, column 9, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  netscaler.adc.nsip:
    <<: *nsip_defaults
        ^ here
NOTICE: To resume at this test target, use the option: --start-at nsip
FATAL: Command "ansible-playbook nsip-8fm3qycu.yml -i inventory" returned exit status 4.
make: *** [test_int] Error 1

```

Please help to solve this error.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 8:09am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/2 "2024-01-02T08:09:18Z")

</div>

YAML anchors do not work over multiple files. (That has nothing to do with ansible-test, that’s something YAML specific.)

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 8:13am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/3 "2024-01-02T08:13:23Z")

</div>

Gathering facts cannot be disabled to my knowledge. If you need more control over the environment, you might want to use `runme.sh`-based tests and run ansible-playbook in them yourself.

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 8:17am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/4 "2024-01-02T08:17:36Z")

</div>

Thank you for your quick reply @felixfontein.

Can you please help me with a sample repo using `runme.sh`?

Also, I am writing integration-tests to `netscaler.adc` collection.

I would like to run a github-action integration test on every pull-request. Are you aware of any github-action examples please?

Sumanth

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 10:54am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/5 "2024-01-02T10:54:40Z")

</div>

For an example using GitHub Actions see: [collection\_template/.github/workflows/ansible-test.yml at main · ansible-collections/collection\_template · GitHub](https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml)

For an runme.sh example see for example [community.general/tests/integration/targets/lookup\_etcd3/runme.sh at main · ansible-collections/community.general · GitHub](https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/lookup_etcd3/runme.sh). If `runme.sh` is present, that one is executed instead of treating the directory as a role. In the shell script you can do things like installing dependencies etc. This is especially needed for testing callback and connection plugins, which you cannot simply test in a role. (Look at tests for these kind of plugins, then you see more instances.)

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 11:23am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/6 "2024-01-02T11:23:23Z")

</div>

Thanks again for your response @felixfontein

I am not understanding the error `./runme.sh: line 7: ../../init.sh: No such file or directory`

## Context:

Collection Repo: [GitHub - netscaler/ansible-collection-netscaleradc: Custom Ansible modules for NetScaler ADC and NetScaler ADM. Part of NetScaler Automation Toolkit | https://github.com/netscaler/automation-toolkit](https://github.com/netscaler/ansible-collection-netscaleradc)

```bash
❯ tree tests/integration                                                                                                                                                                                        
tests/integration                                                                                                                                                                                               
├── ansible.cfg                                                                                                                                                                                                 
├── init.sh                                                                                                                                                                                                     
├── integration_config.yml                                                                                                                                                                                      
├── inventory                                                                                                                                                                                                   
└── targets                                                                                                                                                                                                     
    ├── ipset                                                                                                                                                                                                   
        ├── ipset.yaml                                                                                                                                                                                          
        └── runme.sh                                                                                                                                                                                            

```

I need to save the netscaler API authentication via environment variables.  
I have written `tests/integration/init.sh` to read `tests/integration/integration_config.yml` as below

```bash
❯ cat tests/integration/init.sh
# set the environment variables
export NETSCALER_NSIP=$(cat integration_config.yml | grep nsip | awk '{print $2}')
export NETSCALER_NITRO_USER=$(cat integration_config.yml | grep nitro_user | awk '{print $2}')
export NETSCALER_NITRO_PASS=$(cat integration_config.yml | grep nitro_pass | awk '{print $2}')
export NETSCALER_NITRO_PROTOCOL=$(cat integration_config.yml | grep nitro_protocol | awk '{print $2}')
export NETSCALER_VALIDATE_CERTS=$(cat integration_config.yml | grep validate_certs | awk '{print $2}')
export NETSCALER_SAVE_CONFIG=$(cat integration_config.yml | grep save_config | awk '{print $2}')

```

```bash
❯ cat tests/integration/integration_config.yml
---
nsip: 10.10.10.10
nitro_user: nsuser
nitro_pass: verysecretpassword
nitro_protocol: https
validate_certs: false
save_config: false

```

```bash
❯ cat tests/integration/targets/ipset/runme.sh                                                                                                                                                                  
#!/usr/bin/env bash                                                                                                                                                                                             
                                                                                                                                               
source ../../init.sh                                                                                                                                                                                            
                                                                                                                                                                                        
exec ansible-playbook ipset.yaml    

```

```bash
❯ ansible-test integration ipset
Running ipset integration test script

./runme.sh: line 7: ../../init.sh: No such file or directory

[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
 ________________________ 
< PLAY [Sample Playbook] >
 ------------------------ 

 ____________________________ 
< TASK [Sample Task | ipset] >
 ---------------------------- 

fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: nsip"}
 
< PLAY RECAP >
 

localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0   

NOTICE: To resume at this test target, use the option: --start-at ipset
FATAL: Command "./runme.sh" returned exit status 2.

```

I am not understanding the error `./runme.sh: line 7: ../../init.sh: No such file or directory`

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 11:52am UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/7 "2024-01-02T11:52:41Z")

</div>

I see that ansible creates a temporary folder for this integration test and my `init.sh` is not included in the temporary folder

```bash
/Users/sumanth/.ansible/collections/ansible_collections/netscaler/adc/tests/output/.tmp/integration/
└── ipset-w89nvo37-ÅÑŚÌβŁÈ
    └── tests
        └── integration
            ├── integration.cfg
            ├── integration_config.yml
            ├── inventory
            └── targets
                └── ipset
                    ├── ipset.yaml
                    └── runme.sh

```

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 12:17pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/8 "2024-01-02T12:17:39Z")

</div>

You could symlink `init.sh` into that directory, then it will be copied along.

You could also add `needs/file/init.sh` to the test’s `aliases` file to tell ansible-test that it should copy it along.

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 12:25pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/9 "2024-01-02T12:25:25Z")

</div>

I copied the the below to `aliases` file. Still there is no `init.sh` in the ansible temporary directory.  
☹

```auto
❯ cat tests/integration/targets/ipset/aliases
needs/file/tests/integration/targets/init.sh

```

I read in the below doc that the PATH should be relative to the git root directory.

[https://docs.ansible.com/ansible/latest/dev\_guide/testing/sanity/integration-aliases.html#dependencies](https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/integration-aliases.html#dependencies)

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 12:32pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/10 "2024-01-02T12:32:29Z")

</div>

I changed the `init.sh` to `tests/integration` instead of `tests/integration/targets` and changed the alias accordingly. It worked.

Thank you for your help @felixfontein

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 12:41pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/11 "2024-01-02T12:41:15Z")

</div>

You originally mentioned that `init.sh` in `tests/intrgration`. Your `needs/file/` statement claims it is in `tests/integration/targets`.

---

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [January 2, 2024, 12:51pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/12 "2024-01-02T12:51:29Z")

</div>

I didnt understand your last comment @felixfontein

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 2, 2024, 3:27pm UTC](https://forum.ansible.com/t/defaults-main-yaml-is-not-being-considering-in-ansible-test-integration/3119/13 "2024-01-02T15:27:17Z")

</div>

My comment referred to

> [@sumanth-lingappa](#):
>
> I copied the the below to `aliases` file. Still there is no `init.sh` in the ansible temporary directory.

where it was in the wrong directory.
