General Ansible advise: if you just feed all your command lines in shell
tasks in Ansible, then you are doing it wrong.
Ansible does have existing module, that are purposed to serve the idempotency idea that is at the root of Ansible goal and that will greatly simplify all tasks you will try to achieve.
This being said, you now have to understand what that specific line of the Docker manual is trying to achieve.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg
This command would add the GPG key of Docker to a trusted keyring on the node, so it can validate the authenticity of the package you will later use in a package
task.
So the purposed module, in this case is the apt_key
one.
Your task ends up being:
- name: add docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg