--- - name: get list of running launchd services command: launchctl list register: launchd_running_services changed_when: false - name: determine if system-info is currently running set_fact: system_info_debug: true system_info_plist_path: '{{ansible_env.HOME}}/Library/LaunchAgents/system-info.plist' system_info_running: "{{'system-info' in launchd_running_services.stdout}}" - name: install system-info launchd plist template: src: system-info.plist.j2 dest: '{{system_info_plist_path}}' register: system_info_plist - name: unload running system-info launchd service when: system_info_plist.changed and system_info_running command: 'launchctl unload -w {{system_info_plist_path}}' - name: load system-info launchd service when: system_info_plist.changed or not system_info_running command: 'launchctl load -w {{system_info_plist_path}}'