Let’s look back at the network and system computing age when server deployment and management were daunting tasks for companies. Then, only the system administrator was responsible for software installation, settings management, and all other administration services manually on various servers. It was almost impossible to manage workloads manually and always needed to put the extra effort to complete the tasks.
To overcome these repetitive, complex, and tedious operations, Ansible, an IT automation engine, was created. It uses a simple YAML configuration language that is easy to learn and understand.
Michael DeHaan, the creator of Ansible Work, already had a lot of experience with other configuration management tools when he decided to develop a new one. He said that he wanted “A tool that you could not use for six months, come back to, and still remember.”
Ansible can support one or more nodes, which are computers that attach to the “master node” that must be installed with the Ansible package. The way Ansible works is by connecting to your slave nodes, a computer that is connected with the Ansible control center, and pushing out small programs, called “ansible modules” to them. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules, over Secure Shell (SSH) by default, and removes them when finished the only thing we need ensure that the Master node must be able to access the slaves over an SSH port and must be having required access to complete the tasks.
Before you work through this tutorial, you’ll need:
Next, install Ansible using your preferred method.
Once the installation is complete, confirm the version of the Ansible using the below command in your terminal:
Now let’s create our first inventory file where we store the information of slave/managed nodes with the following commands:
Each notation means the following:
We can use other formats also while creating the inventory files.
Below is how you’ll create a playbook (playbook is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement) to run the automation:
name: Run an Script
hosts: all remote_user: root tasks: – name: Transfer the script copy: src=status.sh dest=/root mode=0777 – name: Execute the script command: sh /root/status.sh – name: Remove file (delete file) file: path: /root/status.sh state: absent |
Create the “vim status.sh,” a bash script, to touch the file on the slave/node servers:
#!/bin/bash
touch /root/text.txt
The Playbook
When we run the above ansible-playbook with the inventory file from earlier, it will check the host entries and try logging it with the defined user with the password we mentioned in the inventory file. Once the SSH connection is established, it will transfer the script to the node servers and execute it using the command provided in the playbook. Once it’s done, it will delete the script from the node/slave servers.
Before we proceed with running the playbook, we must modify the setting so that we can establish the connection without any errors as we are using user-based login.
Go to the Ansible configuration file, “/etc/ansible/ansible.cfg.” Edit the below parameter so that it reads, “false,” like below:
host_key_checking = False
Once the changes are complete, you’ll want to save the file. Now test the connection using the below command:
ansible slave -m ping -i inventory.txt
Successful pong status means it has connected properly from the node/slave server.
Let’s run the playbook using the below command:
ansible-playbook playbook_script.yaml -i inventory.txt
I hope my short introduction and tutorial to Ansible illustrates how this automation tool is designed to be reliable, agentless, and helps you thrive in the automation market. If you really want to master Ansible, make sure to find a project or a course as practice makes perfect.
]]>“Operating system” (or OS) is a phrase that everyone in IT knows. The first thing that clicks in most of our minds when we think of an OS is Windows, but many OSes available in the market give you a similar experience to Windows. Most developers, coders, or system administrators use services like Hypervisors or Virtual Box because of their ability to run multiple OSes inside a single host OS. The issue with these solutions is that they are very bulky in size and consume more space thereby utilizing a heavy amount of resources to run. This prompts the question about whether there’s an alternative – does something similar exist in a more lightweight way?
Docker is just like an OS platform – without a whole OS. Instead, Docker uses OS-level virtualization to carry software in packages called containers. Containers are isolated from each other and have their own libraries, packages, and software, and communicate with their defined channels or mediums.
There are many tutorials available online that will provide you with basic to advanced knowledge of Docker and how it works on Linux. This article, however, will provide you with an understanding of Docker in Windows and how effective it is when compared to industry level use for servers.
Containers are software in packages with their own OS-level architecture. In housing their own libraries of OSes, containers are flexible, standalone, lightweight, secure, and includes everything needed to run your apps.
Docker in Windows can be downloaded from the Docker website and is very easy to install compared to Linux because it’s not a command base. After installation, Docker will only run Linux-mode virtualization with its own MobyLinuxVM by default. It also uses own set of configurations and build up by default, but you can change it. By going to Docker → Setting → Advanced, you can scale the VM as per your use.
To work in Docker with Windows, you need to switch Docker to Windows virtualization, which you can do on right-clicking on Docker bar inside the notification tray and simply click on Switch to Windows Containers. To download software in packages, you can use the Kitematic tool in Docker. This needs to be installed as per the instructions mentioned on the website. Alternatively, you can simply download from Docker store.
There are more than 19,000 software packages available for Windows and more than 200,000 packages for Linux, where you can download Windows IIS servers to MSSQL servers for hosting purposes. The images there are bulkier than Linux images but they are lightweight compared to the original Windows exe images.
For hosting in Windows with Windows IIS inside a Docker platform, we need to download Windows IIS image. We can do this with the following command run in the command prompt:
>docker pull mcr.microsoft.com/windows/servercore/iis
You can check on if the Docker image is downloaded or not with the command:
> docker image ls
After testing, you can run the image simply by using the command below:
>docker run -d -p 8000:80 --name perficient-example iis-site
To verify if the default site is loading or not, you can browse the website in your browser. You require the IP address to do this as the Windows IIS website currently can’t be loaded with localhost input because of WinNAT exception. Docker documentation assures that this will be fixed in the future.
To extract the IP address from the running container, you can run the following command:
>docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" perficient-example
Note: The name should be the same as in the Docker run command. If it’s not, it will throw you an incorrect value or exception error.
To simply browse the site, use the below URL in your browser with the mapped port as in the run command.
>curl -I http://192.168.0.5:8000
We can also run an existing .Net MVC application in Docker containers. To do this, you just need to follow the instructions as provided in this link from Microsoft.
We can also run SQL Server with a combination of IIS. To do this, we just need to pull the image again from the Docker store with the below command.
>docker pull microsoft/mssql-server-windows-expres
And then, to run the SQL server, run the below command:
>docker run -d -p 1433:1433 -e sa_password=<sa_password> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express
This will set up a SQL server with a password. You can then log in to SQL server by running SSMS in Windows with the SQL server container IP, username, and password that have been assigned.
“If you really want to master Docker, make sure to find a project or a course as practice makes a man perfect.”
]]>