Install Software's while provisioning azure vm using Ansible - azure

I am trying to Create a azure windows VM using ansible and while doing so i would like to install jfrog cli or run a powershell script which can do it.
I have a play book which can create a vm, create an vm extension and also create an image out of it. But i do not know how to install software's in that vm, before creating a image.

If you are working on azure windows VMs at your work, you can package your applications which are in .exe and .msi format into chocolatey .nupkg format and host a chocolatey nuget-hosted repo in the artifacts storage application like nexus where you can push and later source and install these chocolatey .nupkg packages that you want to install in these VMs using win_chocolatey ansible module.
Sample task to install a chocolatey package:
- name: "install packages from internal choco nexus repo"
win_chocolatey:
name: "{{ item.name }}"
version: "{{ item.version }}"
loop:
- { name: 'jdk8', version: '8.0.xxx' }
- { name: 'msbuildtools', version: 'xxx' }
win_chocolatey ansible module: https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html
What is chocolatey?
Is is a framework to package applications which are in .exe or .msi formats into .nupkg
(nuget packages) which will have a installation script within the package and
when you run choco commands to install a certain application, it either get
chocolatey packages from opensource chocolatey gallery or for organization
purpose you might want to create custom package for network and security reasons.
Chocolatey Documentation: https://chocolatey.org/why-chocolatey
How to create custom/offline chocolatey packages?
https://chocolatey.org/docs/how-to-create-custom-package-templates
Basic Chocolatey commands:
choco install <package-name> --version <version> -y --> by default gets choco packages from https://chocolatey.org/api/v2/
choco uninstall <package-name> -y --> to uninstall a package. --version option can also be used if a package of multiple versions have been installed
choco source add -n=<AnyName> -s="<URL-Internal-choco-repo>" --> adds internal chocolatey nuget-hosted nexus repos to chocolatey source on windows machines
choco source list --> Lists all added sources from where it gets packages
choco source remove -n="<NameOfSource>" --> To delete any source for list of all the chocolatey sources
Chocolatey commands: https://github.com/chocolatey/choco/wiki/CommandsSources

Related

install python3 on VM without using internet

I need to install python 3 on my virtual machine (I have python 2.7) but I don't have access to internet from my VM. Is there any way to do that without using internet I have access to a private gitlab repository and private dokcer hub.
Using GitLab
Ultimately, you can put whatever resources you need to install Python3 directly in GitLab.
For example, you could use the generic packages registry to upload the files you need and download them from GitLab in your VM. For example, you can redistribute the files from python.org/downloads this way.
If you're using a debian-based Linux distribution like Ubuntu, you could even provide the necessary packages in the GitLab debian registry (disabled by default, but can be enabled by an admin) and just use your package manager like apt install python3-dev after configuring your apt lists to point to the gitlab debian repo.
Using docker
If you have access to dockerhub, technically you can access files from docker images as well. Here I'll assume you're using ubuntu or some debian-based distribution, but the same principle applies for any OS.
Suppose you build an image:
FROM ubuntu:<a tag that matches your VM version>
# downloads all the `.deb` files you need to install python3
RUN apt update && apt install --download-only python3-dev
You can push this image to your docker registry
Then on your VM, you can pull this image and extract the necessary install files from /var/cache/apt/archives/*.deb in the image then install using dpkg
Extract files from the image (in this case, to a temp directory)
image=myprivateregistry.example.com/myrepo/myimage
source_path=/var/cache/apt/archives
destination_path=$(mktemp -d)
docker pull "$image"
container_id=$(docker create "$image")
docker cp "$container_id:$source_path" "$destination_path"
docker rm "$container_id"
Install python3 using dpkg:
dpkg --force-all -i "${destination_path}/*.deb"

Installing packages from Azure DevOps Artifact Feed in a Azure Pipeline

I have two repositories.
The first is built by AzureDevOps Pipelines into a whl file and published on a Azure DevOps Artifact feed. (works)
The second should also be built by AzureDevOps Pipelines and published on Azure DevOps artifacts -> but it is dependend on the first one and needs to install it from the AzureDevops Artifact feed during the build-process. (this does not work).
I can install it locally, but the pipeline of the second package fails. When the pipeline fails, I get the following error:
401 Client Error: Unauthorized for url:
https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<some-numbers>/pypi/download/<mypackage>/0.0.1.9/<mypackage>-0.0.1.9-py3-none-any.whl#sha256=<some-numbers>
---------------------------------- SETUP ----------------------------------
I added the feed as a secondary source to the pyproject.toml of my second repository, this allows me to successfully install the first package with poetry add <firstpackage> and poetry install for my local IDE:
[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/"
secondary = true
YAML script to install packages via poetry - works for the first repository, but not for the second repository which needs to install the first package from the Azure DevOps artifcats feed (the first installs everything from pypi.org):
- script: |
python -m pip install -U pip
pip install poetry==1.1.3 # Install poetry via pip to pin the version
poetry install
displayName: Install software
YAML script to publish a package to an Azure DevOps artifact feed (with a personal access token as authentification) - works:
- script: |
poetry config repositories.azure https://pkgs.dev.azure.com/<company>/<somenumbers>/_packaging/<feed-name>/pypi/upload/
poetry config http-basic.azure usernamedoesnotmatter $(pat)
poetry publish --repository azure
exit 0
displayName: Publish package
I am not checking my Personal Access Token (PAT) into my repository.
pyproject.toml (partial):
[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/"
secondary = true
I added the PipAuthenticate#1 task that sets the PIP_EXTRA_INDEX_URL environment variable that contains a PAT. In the script, I extract the PAT and use it to configure poetry.
azure-pipelines.yaml (partial):
- task: PipAuthenticate#1
displayName: 'Pip Authenticate'
inputs:
artifactFeeds: '<some-numbers>/<feed-name>'
onlyAddExtraIndex: True
- script: |
python -m pip install --upgrade pip
pip install poetry
export PAT=$(echo "$PIP_EXTRA_INDEX_URL" | sed 's/.*build:\(.*\)#pkgs.*/\1/')
poetry config http-basic.azure build "$PAT"
poetry install
displayName: "Install dependencies"
Turns out, I just needed to configure poetry in the pipeline before the install for the second repository - same as I did locally, some long time ago (and forgot about it).
- script: |
python -m pip install -U pip
pip install poetry==1.1.3 # Install poetry via pip to pin the version
# configuring the feed as a secondary source for poetry
poetry config repositories.azure https://pkgs.dev.azure.com/<company>/<some-numbers>/_packaging/<feed-name>/pypi/simple/
poetry config http-basic.azure userNameDoesntMatter $(pat)
poetry install
displayName: Install software

How to install the latest version of NuGet.exe CLI in Ubuntu 18.04 WSL?

I have WSL 18.04 (Ubuntu) and I want to use NuGet.exe to install a Nuget Package to a folder (not .csproj) using the code below:
nuget install Test.Nuget.Version -OutputDirectory packages
In WSL, I use sudo apt install nuget. However that will only install an old nuget version 2.8.xxx in Ubuntu. =(
In order to run nuget install command, I must use the latest version of NuGet version (5.x.x) installed in Ubuntu.
Is it possible to install latest NuGet version in Ubuntu?
If yes, how can I do so?
Normally you can get nuget to update itself:
nuget.exe update -self
However recently, because I assume they have updated the min TLS version, one can get the following error:
The authentication or decryption has failed.
Error while sending TLS Alert (Fatal:InternalError): System.IO.IOException:
So your nuget version has to be new enough to upgrade itself.
So you have to get a new nuget.exe by alternative means:
curl https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -o nuget.exe

aws-cli portable for windows?

this is probably not a big issue for most people but do you know if there is anywhere a portable version for windows of aws-cli.
This because some people might want to install it for example in company laptops and not have admin rights to do it so I was wondering if I could find a portable version somewhere.
edit
could not find a proper portable software version for it but if you manage to install python and use pip then the installation following the instructions in github are quite easy.
final update
I was quite lucky because my company just introduced python as a tool that they allow us to install so I managed to use pip.
the only thing I needed to consider was the user flag so it installs where I have permissions:
pip install --user awscli
pip install --target=YOUR_PATH awscli
As of April 2021, there is only awscli version 1 available in pip repositories. If you want to use awscli version 2 but you don't want to use chocolatey or you don't have another windows machine available, you can:
download the .msi file from Amazon website: https://awscli.amazonaws.com/AWSCLIV2.msi
use msiexec in command line to extract application from msi package:
msiexec /a %USERPROFILE%\Downloads\AWSCLIV2.msi /qb TARGETDIR=%USERPROFILE%\awscli
Now you can use awscli version 2 using the following command:
>%USERPROFILE%\awscliv2\Amazon\AWSCLIV2\aws --version
aws-cli/2.1.39 Python/3.8.8 Windows/10 exe/AMD64 prompt/off
As this method is a workaround, an feature request has been raised to be able to install awscli without admin rights: https://github.com/aws/aws-cli/issues/4633
This is how I've gotten around this issue in the past:
I downloaded (.msi) and install AWS CLI onto my personal laptop then I copy this entire directory (/Amazon/AWSCLI/..) to my corporate laptop where I don't have Admin rights. Then you can either temporarily update the PATH environment variable in your cmd/powershell session or you can permanently update your user variable's PATH to include the location of aws.exe.
It appears you will have to use the aws.exe under /bincompat (instead of /bin) as of their newest release. I haven't yet tested this version to see what limitation exists.
I'm not sure what 'Portable' level you're expecting, but you may find these resources helpful
Chocolatey AWS Tools etc..
Or if you are using Docker
Create a Docker image for the Amazon Web Services CLI that provides a portable, contained experience.

Upgrade Terraform version

I'm start using Terraform and I'm following the project updates on his Github repository.
I see new releases are available on releases section:
https://github.com/hashicorp/terraform/releases
I installed Terraform tool following the steps:
https://www.terraform.io/intro/getting-started/install.html
The new releases are a zip file with base code but I want to know how I can install it on my computer (OSX). What I downloaded when I installed for the first time was a zip file with just a "terraform" file as unix executable.
How I can generate this Unix executable from the zip available on the github releases section?
Any idea?
Thank you!
If you use Homebrew on MacOS already, you can install Terraform simply by
$ brew install terraform
and upgrade by
$ brew upgrade terraform
In fact, you might be interested in letting Homebrew also control other tools:
$ brew install awscli
$ brew install packer
$ brew cask install docker
$ brew cask install virtualbox
$ brew cask install vagrant
There are packages for each OS available on the Downloads Page.
Pick the appropriate package for your OS and download the zip file.
Extract the contents of the zip file, which should be a single terraform binary, into some reasonable location that's in your PATH (e.g. /usr/local/bin).
Add execute permissions: e.g. chmod u+x /usr/local/bin/terraform.
Run terraform and make sure you see the help text.
You could download the binary :
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
then :
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
then :
mv terraform /usr/local/bin/
make sure to change ${TERRAFORM_VERSION} by the version you want to install
exemple :
0.13.2
**TLDR:
for Installation - brew install terraform
for Upgrade - brew upgrade terraform
for Verification - terraform --version
i'm new to using terraform, but to use terraform with multiple versions i use tfenv as terraform version manager
tfenv command
$ tfenv
tfenv 2.2.3
Usage: tfenv <command> [<options>]
Commands:
install Install a specific version of Terraform
use Switch a version to use
uninstall Uninstall a specific version of Terraform
list List all installed versions
list-remote List all installable versions
version-name Print current version
init Update environment to use tfenv correctly.
pin Write the current active version to ./.terraform-version
terraform currently i use
$ terraform -version
Terraform v1.1.9
on linux_amd64
list of terraform i have
$ tfenv list
1.2.0-rc2
* 1.1.9 (set by /home/takimi/.tfenv/version)
change terraform version
$ tfenv use 1.2.0-rc2
and if you want to use another terraform version you just install it with command tfenv install <terraform version>
Adding this response for the sake of completeness.
Hashicorp came up with their own brew taps for all Hashicorp products for MacOS platforms.
to upgrade ...
brew upgrade hashicorp/tap/{vault|consul|nomad|terraform|packer}
to install ...
brew install hashicorp/tap/{vault|consul|nomad|terraform|packer}
Reference : https://www.hashicorp.com/blog/announcing-hashicorp-homebrew-tap
This is detailed in the repository README under 'Developing Terraform' HERE
Essentially...
Ensure you've installed the GO programming language (version 1.7+ at the time of writing).
Create a GO workspace directory.
Create the $GOPATH environment variable pointing to the GO workspace directory you just created.
Add $GOPATH/bin to your $PATH
Clone the Terraform repo (or extract zip) to $GOPATH/src/github.com/hashicorp/terraform
Run make dev within the Terraform repo.
The Terraform binary should be created in $GOPATH/bin
I would recommend you follow the steps in the README as opposed to what I've written above it's comprehensive and may change.
You shouldn't need to do any of this unless your actively developing Terraform, otherwise stick with the installation method in the getting started guide.
To work with multiple Terraform versions, I'm using tfswitch. This allows you to switch between the terraform versions which makes things much easier.
You can find the documentation here.
I was able to use this tool to manage terraform versions: https://github.com/Zordrak/tfenv. The first step was to remove the existing installation with: rm '/usr/local/bin/terraform'
You could use something like asdf or tfenv to manage the terraform binaries.
Gives you the advantage of having the option to use different version per project if required.
$sudo apt-get upgrade
it will work in linux if you have setup right path for terraform

Resources