- set_fact:
    launch_agent: {}

- name: create directory
  file:
    dest:  '{{ home_path }}/Library/LaunchAgents'
    state: directory

- name: copy launch agents
  copy:
    src:  '{{ item }}'
    dest: '{{ home_path }}/Library/LaunchAgents/'
  loop_control:
    label: '{{ item | basename }}'
  with_fileglob:
    - '{{ launch_agent.plist_dir }}/*.plist'
  when: launch_agent.plist_dir

- name: load launch agents
  command: |
    launchctl load "{{ home_path }}/Library/LaunchAgents/{{ item | basename }}"
  loop_control:
    label: '{{ item | basename }}'
  with_fileglob:
    - '{{ launch_agent.plist_dir }}/*.plist'
  when: launch_agent.plist_dir

- set_fact:
    launch_agent: {}

- name: create directory
  file:
    dest:  '{{ home_path }}/Library/LaunchAgents'
    state: directory

- name: copy launch agents
  copy:
    src:  '{{ item }}'
    dest: '{{ home_path }}/Library/LaunchAgents/'
  loop_control:
    label: '{{ item | basename }}'
  with_fileglob:
    - '{{ launch_agent.plist_dir }}/*.plist'
  when: launch_agent.plist_dir

- name: load launch agents
  command: |
    launchctl load "{{ home_path }}/Library/LaunchAgents/{{ item | basename }}"
  register: launchctl_load
  loop_control:
    label: '{{ item | basename }}'
  with_fileglob:
    - '{{ launch_agent.plist_dir }}/*.plist'
  until: launchctl_load.stderr == ""
  retries: 1
  delay: 0
  when: launch_agent.plist_dir

Make launchctl load fail properly
Make launchctl load fail properly
