title: Login into azur cli for a service principal
body: <p>I'm trying to get my ansible script to get logged into azure via azure cli. For some reasons, I'm not allowed to use the ansible azure package. I have to use the shell and call directly the commands from there.</p>
  <p>I'm fairly new with azure in general, so all this tenants, service principals and such are still concepts that I don't fully grasp.</p>
  <p>I've been checking <a href="https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest#logging-in-with-a-service-principal" rel="noreferrer">official the documentation</a>. I've created an app registration for it (Named ansible_test). I get all I need, including the secret. and then I call the the commands as this:</p>
  <pre><code>az login --service-principal -u $AZURE_SERVICE_PRINCIPAL_NAME -p $AZURE_SECRET --tenant $AZURE_TENANT
  </code></pre>
  <p>where:</p>
  <pre><code>$AZURE_SERVICE_PRINCIPAL_NAME = ansible_test
  $AZURE_SECRET = ${The one that I've defined via Certificates &amp; secrets section in the app registration}
  $AZURE_TENANT = ${The azure tenant that I find in the app registration}
  </code></pre>
  <p>I'm getting the error:</p>
  <pre><code>Get Token request returned http error: 400 and server response: {&quot;error&quot;:&quot;unauthorized_client&quot;,&quot;error_description&quot;:&quot;AADSTS700016: Application with identifier 'ansible_test' was not found in the directory '${AZURE_TENANT}(Blurred because I'm not sure this is something secret or not)'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
  </code></pre>
  <p>As I understand, I got the wrong tenant. But I'm getting the exact one that I'm getting from the app registration. I've been hitting my head against this wall for some time. I've tried many other things, but it doesn't seem to work.</p>
  <p>In this image, I'm trying to show that I've indeed created the app registration (What I'm understanding that it's a service principal). I've blurred the ids just out of ignorance whether they are private or not.</p>
  <p><a href="https://i.stack.imgur.com/GQ2vN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GQ2vN.png" alt="Overview of the app registration that I've created called ansible_test" /></a></p>
  <p>What is that I'm doing wrong? I can't really understand the origin of the error...</p>