Skip to main content

How to Connect Windows with Ansible?

Hello Techies, this blog is the continuation of the last blog Install Ansible on Windows which is the second part of the series Ansible with Windows. Before you proceed, I recommend you to please take a look at the introductory blog of this series so to have an understanding of this series.

So, in the previous blog of we understand how to install Ansible on Windows platform. Now, in this blog we will see how we can connect the Ansible Controller (WSL) with the Windows host and do some operations.  As our environment is already setup, there are few steps we need to follow before we can test pinging the windows host and create our first playbook to make some changes on the same host.

Steps to follow:

1. Open Ubuntu App, switch to sudo and change directory to etc and there create Ansible folder.
Ubuntu Root User

2. Then we need to create a configuration file for ansible. Type vim ansible.cfg under /etc/ansible and then type “I” to insert and type. 
Ansible Configuration File

You can add additional configurations as per your requirements. You can find configuration here.

3. Now we need to create a host file which includes the details of the target machine. Here [app] signifies a group, and [app:vars] signifies additional information (variables) to be used for the connection with target host.
Ansible Hosts

4. Now, we will try to ping the windows host, to see whether our Ansible Controller is communicating with our Target Host. So, let us ping now. 
Ping Windows using Ansible

Here, ansible is using the win_ping module to ping the app (our group name in host file which consist our Target Host IP) and we successfully pinged our Target Host from our Ansible Controller.

Now, we will create the playbook to interact with Target Host and do some changes. Type vim create_file_and_folder.yml and insert:

---
- name: Playbook to create folder, file and file with content
  hosts: app
  tasks:
	- name: Create a Folder
	  ansible.windows.win_file:
      	path: '{{ ansible_env.SystemDrive }}\ansible_folder'
      	state: directory
      
	- name: Create a Sub-Folder
	  ansible.windows.win_file:
      	path: '{{ ansible_env.SystemDrive }}\ansible_folder\ansible_sub_folder'
      	state: directory
      
	- name: Create a File
	  ansible.windows.win_file:
      	path: '{{ ansible_env.SystemDrive }}\ansible_folder\file1.txt'
      	state: touch
      
	- name: Create a file with content
	  ansible.windows.win_copy:
      	dest: '{{ ansible_env.SystemDrive }}\ansible_folder\file2.txt'
      	content: |
        	This is Line 1
        	This is Line 2
...

Now, we will run this playbook. The playbook can be run using ansible-playbook command.

Ansible Playbook

The playbook ran successfully and also stated that the status of the tasks is changed. Now, if you look at the directory you will see all the folders and file created automatically using Ansible on Target Host (Windows) machine.


So, this is just a small example to make you understand how you can use Ansible to communicate with any target host and make changes automatically. Apart from this small task you can use Ansible to automate Infrastructure, Applications, Security, Networks, Cloud and Containers. Hope, this blog helps you to have an understanding of how to create host file, playbook and how to run the playbook.

About Amlgo Labs : Amlgo Labs is an advanced data analytics and decision sciences company based out in Gurgaon and Bangalore, India. We help our clients in different areas of data solutions includes design/development of end to end solutions (Cloud, Big Data, UI/UX, Data Engineering, Advanced Analytics and Data Sciences) with a focus on improving businesses and providing insights to make intelligent data-driven decisions across verticals. We have another vertical of business that we call - Financial Regulatory Reporting for (MASAPRAHKMAEBAFEDRBI etc) all major regulators in the world and our team is specialized in commonly used regulatory tools across the globe (AxiomSL Controller ViewOneSumX DevelopmentMoody’s RiskIBM Open Pages etc).We build innovative concepts and then solutions to give an extra edge to the business outcomes and help to visualize and execute effective decision strategies. We are among top 10 Data Analytics Start-ups in India, 2019 and 2020.

Please feel free to comment or share your views and thoughts. You can always reach out to us by sending an email at info@amlgolabs.com
 or filling a contact form at the end of the page.

Comments

More Popular Posts

JavaScript: The Important Basics

In this weird world of technology people often get confused how does a website work? What all things should I be aware of? So we are here to help you. Most of the content on web is developed with the help of JavaScript. JavaScript is really becoming popular these days with the coming of ECMAScript2015 and ECMAScript 2016, for this reason, some beginners learning React and Angular and are also trying to tackle more modern JavaScript syntax at the same time. If you're new to both, it can be confusing as to "what is JavaScript and what are its important features". This document should serve as a primer to help you get up-to-speed on JavaScript syntax that we feel matters the most for learning React as well as Angular.

Amlgo Blog - Experience The Experiments

Amlgo Labs Blog  is a step towards our vision to share knowledge and experiences, Amlgoites accept every challenge very enthusiastically. We do experiments, we fail but we learn and build complex solutions to help our clients solve their problems in Data, Analytics, Prediction, Forecasting, Reporting, Designing and Development area. During this process we enjoy immense learning everyday and we have decided to share our thoughts, learnings, experiments and experiences so that we don't work in silos and contribute the best of our knowledge towards community and learn more by views and reviews. This website is maintained and brough to you by  Amlgo Labs Professionals .   Our Strong Basics -  1)   KISS (Keep It Simple and Straightforward) :  We believe most of the problems can be solved by keeping things simple and straight. This is the learning we had in past, sometimes we try to solve technical problems using high end algorithms and complex codes but this results into complications.

Power BI Blog - What is Power BI and Why we use Power BI.

This Power BI blog is an introduction to the Power BI. In this Power BI tutorial, you will learn Power BI basics - what is Power BI, Power BI Desktop and Power BI Service. Power BI tool is a combination of Business Intelligence and Visualization. Before we dig deep let’s understand what is Business Intelligence. Business Intelligence is a broad spectrum which consists of using different business strategies and techniques to gather data, refine it and process it for the purpose of data analysis which gives us some meaningful information which helps in data driven decision making. When we present this information in the form of some charts, graphs it takes the form of Visualization.

Polybase Blog - Introduction

Overview: This Polybase blog series is all about the use of Polybase Technology in today’s era to be able to take advantage of the Data(Relational and Non-Relational) by using T-SQL only. Data whether Big or not is the lifeline to many different sectors to cope up with Production, Maintenance, Predictions, Taking Precautionary Measures, Customer Satisfaction, Customer Retention, Sales, Revenue Generation and many more.

Stages of New Regulatory Reporting Implementation

In the last blog, we discussed what is  Financial Regulatory Reporting  and its importance in the banking industry. Regulatory Reporting comprises the submission of business numbers as required by regulators to evaluate and track the financial and operational status of financial institutions and their compliance with required regulatory provisions.

Polybase Installation for Scale-Out process

This part is the continuation of the previous blog about the introduction of  Polybase Scale-Out Group . As we have discussed in our earlier blog PolyBase enables your SQL Server instance to process Transact-SQL queries that read data from external data sources. SQL Server 2016 and higher can access external data in Hadoop and Azure Blob Storage. Starting in SQL Server 2019, PolyBase can be used to access external data in SQL Server, Oracle, Teradata, and MongoDB.