- name: Verify lookup_config errors with no on_missing (failure expected)
  set_fact:
    foo: '{{lookup("config", "THIS_DOES_NOT_EXIST")}}'
  ignore_errors: yes
  register: lookup_config_1

- name: Verify lookup_config errors with on_missing=error (failure expected)
  set_fact:
    foo: '{{lookup("config", "THIS_DOES_NOT_EXIST", on_missing="error")}}'
  ignore_errors: yes
  register: lookup_config_2

- name: Verify lookup_config does not error with on_missing=skip
  set_fact:
    lookup3: '{{lookup("config", "THIS_DOES_NOT_EXIST", on_missing="skip")}}'
  register: lookup_config_3

# TODO: Is there a decent way to check that the warning is actually triggered?
- name: Verify lookup_config does not error with on_missing=warn (warning expected)
  set_fact:
    lookup4: '{{lookup("config", "THIS_DOES_NOT_EXIST", on_missing="warn")}}'
  register: lookup_config_4

- name: Verify lookup_config errors with invalid on_missing (failure expected)
  set_fact:
    foo: '{{lookup("config", "THIS_DOES_NOT_EXIST", on_missing="boo")}}'
  ignore_errors: yes
  register: lookup_config_5

- name: Verify lookup_config errors with invalid param type (failure expected)
  set_fact:
    foo: '{{lookup("config", 1337)}}'
  ignore_errors: yes
  register: lookup_config_6

- name: Verify lookup_config errors with callable arg (failure expected)
  set_fact:
    foo: '{{lookup("config", "ConfigManager")}}'
  ignore_errors: yes
  register: lookup_config_7

- name: Verify lookup_config
  assert:
    that:
      - '"meow" in lookup("config", "ANSIBLE_COW_WHITELIST")'
      - lookup_config_1 is failed
      - '"Unable to find setting" in lookup_config_1.msg'
      - lookup_config_2 is failed
      - '"Unable to find setting" in lookup_config_2.msg'
      - lookup_config_3 is success
      - 'lookup3|length == 0'
      - lookup_config_4 is success
      - 'lookup4|length == 0'
      - lookup_config_5 is failed
      - '"must be a string and one of" in lookup_config_5.msg'
      - lookup_config_6 is failed
      - '"Invalid setting identifier" in lookup_config_6.msg'
      - lookup_config_7 is failed
      - '"Invalid setting" in lookup_config_7.msg'
