---
# task file to build macports from source on Darwin

- name: darwin | source | ensure /opt/local/src exists
  file:
    path=/opt/local/src
    owner=root
    group=staff
    mode=0755
    state=directory
  become: yes

- name: darwin | source | check if tarball exists
  stat:
    path="/opt/local/src/{{ macports_tarball }}"
  register: f

- name: darwin | source | download macports tarball
  get_url:
    url={{ macports_tarball_url }}
    dest=/opt/local/src
    sha256sum={{ macports_tarball_sha256 }}
    owner=root
    group=wheel
    mode=0644
  sudo: yes
  when: not f.stat.exists


---
# task file to build macports from source on Darwin

- name: darwin | source | ensure /opt/local/src exists
  file:
    path=/opt/local/src
    owner=root
    group=staff
    mode=0755
    state=directory
  become: yes

- name: darwin | source | check if tarball exists
  stat:
    path="/opt/local/src/{{ macports_tarball }}"
  register: f

- name: darwin | source | download macports tarball
  get_url:
    url={{ macports_tarball_url }}
    dest=/opt/local/src
    sha256sum={{ macports_tarball_sha256 }}
    owner=root
    group=wheel
    mode=0644
  become: yes
  when: not f.stat.exists


Use become instead of sudo
Use become instead of sudo
