1. Нам важно Ваше мнение!
    и обсуждайте вместе! Нажимайте "мне нравится" и рекомендуйте друзьям ;)
    Понравилось тема? Напишите в ней свой отзыв.
    Считаете что тема не достаточно полно раскрыта? Расскажите свою точку зрения!
    С Вашей помощью сделаем форум еще лучше!

Clearwater : vsts teams - Eduard Kabrinskiy

Тема в разделе 'Горячие новости для тех кто следит за собой', создана пользователем SHALOMEn, 19 май 2021.

  1. SHALOMEn

    SHALOMEn Member

    Eduard Kabrinskiy - Ansible in devops - Eduard Kabrinskiy


    <h1>Ansible in devops</h1>
    <p>[youtube]</p>
    Ansible in devops <a href="http://remmont.com">Top stories</a> Ansible in devops
    <h1>Azure DevOps Ansible Pipeline</h1>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2020/06/Azure-DevOps-Ansible-Pipeline.png" /></p>
    <p>I thought it was about time that I started to have a play with Azure DevOps a little more than I have been doing. One of the things I have always meant to look at in the past is using DevOps to run Ansible playbooks.</p>
    <p>However the Ansible Task recommended by Microsoft has always put me off, the reason for this is that this task requires a Virtual Machine to run Ansible ? this to me always seemed a little overkill.</p>
    <p>As I had some time I thought I would sit down and have a look at coming up with a pipeline which executes an Ansible playbook which doesn?t use the Ansible Task. As I had already done some work with Python based command line tools on Azure DevOps I thought it best to take the same approach as I took with those to my Ansible pipeline.</p>
    <p>As you can see, the start of the pipeline is pretty straight foward, I am triggering whenever master is pushed to, and using, the latest Ububtu VM image:</p>
    <p>The next step is to make sure that Python is installed, here I am using Python 3.6:</p>
    <p>So far so good, but the next step had me scratching my head for a little while.</p>
    <p>I knew that I was going to connect the Azure DevOps project to my Azure subscription using a service connection which would grant contributor access, I also knew that I didn?t want to hard code any values in my azure-pipelines.yml file, so how could I make sure that the credentials for the Azure DevOps managed service principle could be securely used by Ansible?</p>
    <p>After a little trial and error, I settled on the task below:</p>
    <p>As you can see, I am using the AzureCLI Task ? this takes a few inputs:</p>
    <p><ul>
    <li><strong>azureSubscription</strong>: This will be the name of the service connection, as I don?t want to hardcode any values here I am using the variable $(SUBSCRIPTION_NAME)</li>
    <li><strong>addSpnToEnvironment</strong>: When set to true this will add service principal id and key of the service endpoint as variables</li>
    <li><strong>scriptType</strong>: As I am using Ubuntu, I set this to ?bash?</li>
    <li><strong>scriptLocation</strong>: Finally, setting ?inlineScript? means that I can define the script within the task</li>
    </ul>
    </p>
    <p>The inline script uses logging commands to take the SPN variables and set them as variables we can use in later tasks:</p>
    <p>You may have noticed that ARM_CLIENT_ID, ARM_CLIENT_SECRET and ARM_TENANT_ID are using the variables from the task which is why they are using the $ <variable>format.</p>
    <p>To populate ARM_SUBSCRIPTION_ID we are using the output of running az account show --query="id" -o tsv which returns the subscription ID, so as we are using Bash the format is $(command here) .</p>
    <p>The great thing about this approach is that because the variables which are outputted by the AzureCLI task are secrets they will always be treated as such so if we were to ever output them they will simply appear as *** though it is important that you are still careful when using them as you do not want the values appearing in any output.</p>
    <p>The next step installs Ansible along with the Azure Modules:</p>
    <p>Now that we have our SPN credentials defined as variables within the pipeline and Ansible installed we can finally run the playbook using the final task:</p>
    <p>As the Azure Ansible modules expect the Azure credentials, tenant and subscription IDs as environment variables we are passing this at run time in the format which Ansible expects, AZURE_CLIENT_ID, AZURE_SECRET, AZURE_TENANT and AZURE_SUBSCRIPTION_ID ? all of which are populated using the pipeline variables which were set in the Azure CLI task.</p>
    <p>Running the pipeline gave me the following output:</p>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2020/06/Image-1-1024x594.png" /></p>
    <p>Step ? Install Python</p>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2020/06/Image-2-1024x594.png" /></p>
    <p>Step ? Azure CLI</p>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2020/06/Image-3-1024x594.png" /></p>
    <p>Step ? Install Ansible and the Azure modules</p>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2020/06/Image-4-1024x594.png" /></p>
    <p>Step ? Run Ansible Playbook</p>
    <p>As you can see from the pipeline output above, the whole pipeline took just over a minute to run, and 50 seconds of that was installing Ansible itself.</p>
    <p>Admittedly the playbook didn?t do much other than create a resource group called ?azuredevops-rg? ? however it wasn?t the playbook I was concerned about in this post ? I just want a good boilerplate azure-pipelines.yml file for future projects.</p>
    <p>If you follow along with this post, make sure that when creating the pipeline in Azure DevOps you create a variable called SUBSCRIPTION_NAME and populate with the name of the Azure Resource Manager service connection your project uses.</p>
    <p>You can find the repository used in this post on GitHub.</p>
    <p style="clear: both"><img src="https://n4stack.io/wp-content/uploads/2018/07/Russ-McKendrick.png" /></p>
    <h4>Russ McKendrick</h4>
    <p>Practice Manager (SRE & DevOps)</p>
    <p>Russ heads up the SRE & DevOps team here at N4Stack.</p>
    <p>He's spent almost 25 years working in IT and related industries and currently works exclusively with Linux.</p>
    <p>When he's not out buying way too many records, Russ loves to write and has now published six books.</p>
    <h2>Ansible in devops</h2>

    <h3>Ansible in devops</h3>
    <p>[youtube]</p>
    Ansible in devops <a href="http://remmont.com">New news today</a> Ansible in devops
    <h4>Ansible in devops</h4>
    A step-by-step guide to creating a pipeline which executes an Ansible playbook which doesn?t use the Ansible Task | Azure | DevOps
    <h5>Ansible in devops</h5>
    Ansible in devops <a href="http://remmont.com">Ansible in devops</a> Ansible in devops
    SOURCE: <h6>Ansible in devops</h6> <a href="https://dev-ops.engineer/">Ansible in devops</a> Ansible in devops
    #tags#[replace: -,-Ansible in devops] Ansible in devops#tags#

    Эдуард Кабринский
    latest news

Поделиться этой страницей