Install Xcode and possibley Command Line Tools also to install compliers needed.
MacOS needs pip resources for the system, as such it's best to ignore upgrading these on the whole system with --ignore-installed
:
sudo pip install --ignore-installed --upgrade ansible