Ansible task write to local log file

Solution 1:

You need to use register in the first task and now, you can create a second task to write the output to a local file

- name: shell command
  shell: my_shell_command
  register: myshell_output
- name: copy the output to a local file
  copy:
    content: "{{ myshell_output.stdout }}"
    dest: "/tmp/hello.txt"
  delegate_to: localhost