In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to configure Podman containers with Ansible". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure Podman containers with Ansible.
In a complex IT infrastructure, there are many repetitive tasks. It is not easy to run these tasks successfully. Most of the failures are caused by human error. With the help of Ansible, you can perform all tasks through remote hosts, which follow the action manual playbook, which can be reused as many times as needed. In this article, you will learn how to install and configure Ansible on Fedora Linux, and how to use it to manage and configure Podman containers.
Ansible
Ansible is an open source infrastructure automation tool sponsored by Red Hat. It can handle all the problems posed by large infrastructure, such as installing and updating software packages, backing up, ensuring that specific services are running continuously, and so on. You use the action manual written by YAML to do these things. The Ansible action manual can be used repeatedly to make the work of the system administrator less complicated. The action manual reduces repetitive tasks and can be easily modified. But we have a lot of automation tools like Ansible, so why use it? Unlike some other configuration management tools, Ansible is agentless: you don't have to install anything on the managed node.
Podman
Podman is an open source container engine for developing, managing, and running container images. But what is a container? Every time you create any new application and deploy it on a physical server, cloud server, or virtual machine, the most common problem you face is portability and compatibility. This is why the container appears. Containers are virtualized at the operating system level, so they contain only the required libraries and application services. The benefits of containers include:
Portability
Isolation
Expansibility
Lightweight
Quick start
Smaller disk and memory requirements
In short: when you build a container image for any application, all necessary dependencies are packaged into a container. You can now run the container on any host operating system without any portability or compatibility issues.
The key highlight of Podman is that it does not have a daemon, so it does not require root permission to run the container. You can build a container image with Dockerfile, or pull an image from Docker Hub, fedoraproject.org, or Quay.
Why configure Podman with Ansible?
Ansible provides a way to easily run repetitive tasks multiple times. It also provides a number of modules for cloud providers (such as AWS, GCP, and Azure), container management tools (such as Docker and Podman), and database management. Ansible also has a community (Ansible Galaxy) where you can find a large number of Ansible characters, Roles, created by contributors from all over the world. Because of these, Ansible has become a good tool in the hands of DevOps engineers and system administrators.
With DevOps, the pace of application development is very fast. It is critical that the applications developed are not limited to any operating system. This is where Podman appears.
Install Ansible
First, install Ansible:
$sudo dnf install ansible-y configure Ansible
Ansible needs to run ssh on the managed node, so first generate a key pair Key Pair.
$ssh-keygen
After the key is generated, copy the key to the managed node.
Enter yes, and then enter the password for the managed node. Managed hosts can now be accessed remotely.
To be able to access the managed node, you need to store all hostnames or IP addresses in the manifest file. By default, this is in ~ / etc/ansible/hosts.
This is what the inventory inventory file looks like. Square brackets are used to assign groups to specific nodes.
[group1] green.example.comblue.example.com[group2] 192.168.100.11192.168.100.10
Check that all managed nodes are reachable.
$ansible all-m ping
You can see the following output:
[mahesh@fedora new] $ansible all-m pingfedora.example.com I SUCCESS {"ansibe_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": false, "ping": "pong"} [mahesh@fedora new] $
Now create your first action manual, playbook, which will install Podman on the managed node. First create a file with any name with the .yml extension.
$vim name_of_playbook.yml
The action manual should look like this. The first field is the name of the action manual. The hosts field is used to refer to the hostname or group name mentioned in the listing. Become: yes indicates upgrade permissions, and tasks contains the task to be performed. Here the name (name) specifies the name of the task (tasks), and yum is the module on which the package is installed. Below, specify the package name in the name field (name), and specify the installation or removal of the package in the status field (state).
-name: First playbook hosts: fedora.example.com become: yes tasks:-name: Installing podman. Yum: name: podman state: present
Check the file for syntax errors:
$ansible-playbook filename-syntax-check
Now run the action manual:
$ansible-playbook filename
You can see the following output:
[mahesh@fedora new] $ansible-playbook podman_installation.ymlPLAY [First playbook] * TASK [Gathering Facts] * 0k: [fedora.example.com] TASK [Installing podman] * * changed: [fedora.example.com] PLAY RECAP * * fedora.example.com: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [mahesh@fedora new] $
Now create a new action manual and pull an image from Docker Hub. You will use the podman_image module to extract the httpd image with version number 2-alpine from Docker Hub.
-name: Playbook for podman. Hosts: fedora.example.com tasks:-name: Pull httpd:2-alpine image from dockerhub. Podman_image: name: docker.io/httpd tag: 2-alpine
Now check the images that have been pulled:
[mahesh@fedora new] $podman imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/library/httpd 2-alpine fa848876521a 11 days ago 57 MB [mahesh@fedora new] $
Create a new action manual to run the httpd image. See the podman_container module documentation for more information.
-name: Playbook for podman. Hosts: fedora.example.com tasks:-name: Running httpd image. Containers.podman.podman_container: name: my-first-container image: docker.io/httpd:2-alpine state: started
Check the running status of the container.
[mahesh@fedora new] $podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES45d966eOe207 docker.io/library/httpd:2-alpine httpd-foreground 13 seconds ago Up 13 seconds ago my-first-container [mahesh@fedora new] $
Now stop the running container and change the state from started to absent.
-name: Stopping httpd container. Containers.podman.podman_container: name: my-first-container image: docker.io/httpd:2-alpine state: absent
When you execute the podman ps command, you don't see any containers that are running.
[mahesh@fedora new] $podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [mahesh@fedora new] $
Podman_container can do many things, such as recreating the container, restarting the container, checking whether the container is running, and so on. For information about performing these operations, refer to the documentation.
At this point, I believe you have a deeper understanding of "how to configure the Podman container with Ansible". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.