If I have something like this:
- include_vars: this_file_doesnt_exist.yml
ansible will throw the error "input file not found at ..." and stop the provisioning process.
I'm wondering if it's possible to allow the provisioning process to continue if the file isn't found.
My use case is the following:
Example:
- include_vars: aptcacher.yml
- name: use apt-cache
template: src=01_proxy.j2 dest=/etc/apt/apt.conf.d/01_proxy owner=root group=root mode=644
sudo: true
when: aptcacher_host is defined
Ansible version: 1.9.1
You can just ignore_errors
on the include_vars
task:
- include_vars: nonexistant_file
ignore_errors: yes
EDIT
With ansible > 1.6.5 I am getting
test.yml
---
- hosts: localhost
tasks:
- include_vars: nonexistent_file
ignore_errors: yes
- debug:
msg="The show goes on"
PLAY [localhost]
GATHERING FACTS *************************************************************** ok: [localhost]
TASK: [include_vars nonexistent_file] ***************************************** failed: [localhost] => {"failed": true, "file": "/home/ilya/spielwiese/ansible/nonexistent_file"} msg: Source file not found. ...ignoring
TASK: [debug msg="The show goes on"] ****************************************** ok: [localhost] => { "msg": "The show goes on" }
You can use with_first_found
to archive this.
- include_vars: "{{ item }}"
with_first_found:
- this_file_doesnt_exist.yml
I'm not 100% sure it will work without complain if not at least one file matched. In case it doesn't work, you will need to add an empty fallback file:
- include_vars: "{{ item }}"
with_first_found:
- this_file_doesnt_exist.yml
- empty_falback.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With