examples/ansible/remove-directory.yml

- hosts: 127.0.0.1
  vars:
    ansible_python_interpreter: /usr/bin/python3

  tasks:
    - name: Remove directory
      file:
        path: /tmp/somedir
        state: absent

ansible-playbook remove-directory.yml

See also Ansible file module.