How to use Service Fabric Powershell cmdlets in an Azure Automation runbook - azure-service-fabric

I want to use an azure automation account to connect to a service fabric cluster and run a health check. I'm struggling with establishing a connection to the cluster because the service fabric sdk is not present.
Is there a way to use the service fabric powershell cmdlets in an azure automation runbook?

You could import AzureRM.ServiceFabric 0.2.4 module to Azure automation account. Open the link https://www.powershellgallery.com/packages/AzureRM.ServiceFabric/0.2.4 and click Deploy to Azure Automation. Then, you could use some Service Fabric PowerShell cmdlets.
Another solution is using Hybrid Runbook Worker.
The Hybrid Runbook Worker feature of Azure Automation allows you to
run runbooks directly on the computer hosting the role and against
resources in the environment to manage those local resources.
You could install fabric cluster SDK on your local, and use Runbook worker to execute it.

Related

How to deploy automatically Azure VMs and AKS on an environment?

I made a Terraform to create an infrastructure on Azure.
I used the provider "microsoft/azuredevops".
I need to add VMs and Azure Kubernetes Service on a specific environment that I created.
My question is how to deploy the script (which put tags) to them ?
It's not possible to deploy it in an Azure DevOps Pipeline because this last doesn't know VMs (and AKS).
I don't see anything else to made it with the provider azuredevops.
The solution (I think) will would be to extract the original script from an environment on Pipeline/Environment. I need to change all variables as personal access token and others too.
But I don't know if Microsoft change the script regularly.
What's the best solution ?
Thank you.
If you want to manage Azure resources with Terraform then you need to use the AzureRM provider not the Azure DevOps provider. The Azure DevOps provider is for managing your Azure DevOps instance.
The AzureRM provider contains resources for managing Linux and Windows VM's or for other types of resource such as AKS
Once you've written your terraform code, you can use a pipeline to run the terraform against Azure. Microsoft provide a terraform extension which can be used to call terraform in your pipeline
For the pipeline to be able to authenticate against Azure you'll need to set up a service connection. This will allow the pipeline to use a service principle in azure which can be given the appropriate level of permissions to create, update, destroy Azure Resources
Hashicorp have a good tutorial on getting started with Terraform and Azure and Microsoft also have some good documentation
Microsoft also have a tutorial on using Terraform from a pipeline, it uses the classic GUI based pipelines rather than YAML but the tasks and principles will be the same for both

Service Fabric Powershell from Azure Devops

I am able to successfully deploy Service Fabric services to my local cluster from Azure Devops using the ServiceFabricDeploy task with a configured service connection. What I need is the ability to run some arbitrary powershell scripts against the fabric in order to perform other maintenance tasks that I want to automate via CI/CD.
How can I get a normal inline powershell task connected to my local fabric so I can interact with the cluster?
You can use the SF PowerShell module for that.
First connect to the cluster.
Next, manage the cluster using the provided functions.
Under water, these commands use the REST API of SF. Therefore you can't just run arbitrary code.
If you want to do that, you'll need to use SSH or something like PowerShell remoting.
More info on how to set it up in the Load Balancer here.

How to automate Azure DevOps Kubernetes Service Connection to Cluster?

To deploy services via Azure Devops to my kubernetes cluster, I need to create a Kubernetes Service Connection manually. I want to automate this by creating the service connection dynamically in Azure DevOps so I can delete and recreate the cluster and deployment. Is this possible? How can I do this?
you can create the service endpoint using the azure devops api,
check this out for api detail
this might be related

Can Ansible watch for new target machines in Azure?

I'm automating the deploying of Azure Resource Groups and Virtual Machines. I'd like to have a Ansible Controller recognize when new VMs are created so that it can run playbooks on them and configure them for me.
How do I get Ansible to recognize new VMs created in Azure
No, Ansible on its own can't do that.
Ansible is an agentless tool that do the job only when you (or some other external system) ask it to.
You have some options:
setup some monitoring system that will watch for new VMs and trigger Ansible playbook runs
setup some cloud events (not sure if there are any in Azure, like CloudWatch Events in AWS) that will trigger your Ansible jobs
setup dynamic inventory for your playbook (that will list all VMs provisioned and new) and run your playbooks with cron Job
setup ansible-pull inside your cloud VM images, so it pulls required playbooks at VM startup and provision machine automatically

Team Services deploy to on-premise Service Fabric without exposed endpoint

We have a Service Fabric cluster on-premise and would like to deploy code to it from Visual Studio Team Services. We use this cluster for testing and it does not have an endpoint exposed to the outside world. It is only accessible internally from inside our network.
From inside Team Services the normal way to deploy a Service Fabric application is with the "Service Fabric Application Deployment" task. This task requires a "Cluster Connection" parameter, or link to the Service Fabric Service endpoint that Team Services can access. On this cluster I can't provide an endpoint to the outside world, so this method won't work.
Is there a good, accepted way of accomplishing this? I'm considering looking at having an Agent on one of the Service Fabric nodes that can run a PowerShell script as part of the build process. I can kick off a PowerShell script on the node as part of the build process. If I could retrieve the artifacts from Team Services with this script I believe the rest of the release would be relatively straightforward.
Is this a good line of thought, or is there a more straightforward way to deploy to Service Fabric from Team Services without exposing an endpoint?
We have the same set up and using VSTS. We set up a On-Prem agent pool where agent is within our network. The agent is hook with VSTS so build and release can be trigger from VSTS. Agent have access to the artifact on VSTS and can download it for deployment. The different might be we set up a service fabric end point instead of using powershell.
Its a very simple set up and works well for us.Good luck