---
- name: "Ensure {{ app_name }} is installed"
  pip:
    name: dns-lexicon[full]
    state: "{{ app_state | default('latest') }}"
    executable: "{{ '/usr/local/bin/pip3' if ansible_system == 'Darwin' else '/usr/bin/pip3' }}"

- name: Ensure configuration file is created
  blockinfile:
    path: "{{ lexicon_config_path }}"
    block: "{{ user.lexicon_config | to_nice_yaml(indent=2, width=1000) }}"
    backup: true
    create: true
    mode: 0700
  loop: "{{ user_configs }}"
  loop_control:
    label: "{{ user.username }}"
    loop_var: user
  when:
    - (user.system is not defined) or ((user.system is defined) and (not user.system))
    - user.lexicon_config is defined