首页 > 其他分享 >ansible 基本介绍

ansible 基本介绍

时间:2023-03-24 17:36:50浏览次数:52  
标签:基本 ... 插件 Ansible 介绍 ansible ssh sshpass

介绍#

Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。

Ansible的特点

  1、ansible不需要单独安装客户端,也不需要启动任何服务
  2、ansible是python中的一套完整的自动化执行任务模块
  3、ansible playbook 采用yaml配置,对于自动化任务执行过一目了然

Ansible组成结构 

ansible是Ansible的命令工具,核心执行工具;一次性或临时执行的操作都是通过该命令执行。
Ansible Playbook
任务剧本(又称任务集),编排定义Ansible任务集的配置文件,由Ansible顺序依次执行,yaml格式。
Inventory
Ansible管理主机的清单,默认是/etc/ansible/hosts文件。
Modules
Ansible执行命令的功能模块,Ansible2.3版本为止,共有1039个模块。还可以自定义模块。
Plugins
插件,模块功能的补充,常有连接类型插件,循环插件,变量插件,过滤插件,插件功能用的较少。
API
提供给第三方程序调用的应用程序编程接口。

ansible 安装

1、ansible 安装   

apt install ansible

2、Ansible Inventory文件

  Inventory文件通常用于定义要管理的主机的认证信息,例如ssh登录用户名、密码以及key相关信息。可以同时操作一个组的多台主机,组与主机组之间的关系都是通过inventory文件配置。配置文件路径为:/etc/ansible/hosts,这里是默认配置,可以自己指定在项目中使用;

使用默认文件添加主机信息,如:

[server]
192.168.108.22 ansible_ssh_port=22 ansible_ssh_user=user1 ansible_ssh_pass="123456"
192.168.108.23 ansible_ssh_port=22 ansible_ssh_user=user1 ansible_ssh_pass="123456"
命令行执行:

        root@master:~# ansible all -m ping -o
        192.168.108.22 | FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}
        192.168.108.23 | FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}
        安装缺少的sshpass 程序;
        root@master:~# apt install sshpass
        Reading package lists... Done
        Building dependency tree
        Reading state information... Done
        The following package was automatically installed and is no longer required:
          tcpd
        Use 'apt autoremove' to remove it.
        The following NEW packages will be installed:
          sshpass
        0 upgraded, 1 newly installed, 0 to remove and 62 not upgraded.
        Need to get 10.5 kB of archives.
        After this operation, 30.7 kB of additional disk space will be used.
        Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 sshpass amd64 1.06-1 [10.5 kB]
        Fetched 10.5 kB in 0s (61.3 kB/s)
        Selecting previously unselected package sshpass.
        (Reading database ... 124960 files and directories currently installed.)
        Preparing to unpack .../sshpass_1.06-1_amd64.deb ...
        Unpacking sshpass (1.06-1) ...
        Setting up sshpass (1.06-1) ...
        Processing triggers for man-db (2.9.1-1) ...
        root@master:~#
        root@master:~#
        root@master:~#

再次进行测试:

root@master:~# ansible all -m ping -o
        192.168.108.22 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": false,"ping": "pong"}
        192.168.108.23 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": false,"ping": "pong"}

3、ansible 参数:

-m 模块,执行命令默认为shell
-a 参数,必须给定;
-u 给定用户执行;

一些用户会受到安全规则的限制,使用 sudo 切换时只能运行指定的命令.这与 ansible的 no-bootstrapping 思想相悖,而且 ansible 有几百个模块,在这种限制下
无法进行正常的工作. 所以执行 ansible 命令时,应使用一个没有受到这种限制的账号来执行;

 

标签:基本,...,插件,Ansible,介绍,ansible,ssh,sshpass
From: https://www.cnblogs.com/juzib/p/17252809.html

相关文章

  • 简单介绍最新python 字符串数组互转问题
    字符串转list数组str='1,2,3'arr=str.split(',')gpu_ids分配name=opt.namegpu_ids=[int(item)foriteminopt.gpu_ids.split(',')]#setgpuidsiflen(gpu_i......
  • DOS介绍以及常用命令
    DOS介绍来自百度百科:dos,是磁盘操作系统的缩写,是个人计算机上的一类操作系统。DOS是1979年由微软公司为IBM个人电脑开发的MS-DOS,它是一个单用户单任务的操作系统。DOS是Disk......
  • 华为、思科命令对比,从基础、交换、路由三大方向介绍
    本文将对配置华为、思科两大厂商的命令进行对比,主要从三大方向来介绍:一、基础命令二、交换命令三、路由命令......
  • python apscheduler 定时任务的基本使用-5-添加任务
    pythonapscheduler定时任务的基本使用-5-添加任务1、添加定时任务可以随时随地添加任务,不论调度器是否启动。如果未启动时,添加了定时任务,则会在调度器启动时,正常执行该......
  • SSD 简介—— NAND 芯片介绍
    制作存储芯片的制作和其他芯片制作大致相同,从沙子中提取单晶硅制作晶圆再封装芯片。闪存芯片从架构上分为NOR和NANDNORFlash的sourceline把每个cell都并联起来,而NAN......
  • Linux下Mysql数据库的基本使用
    (Linux下Mysql数据库的基本使用)一、Mysql的delete删除语法1.删除数据库①使用drop删除mysql>mysql>showdatabases;+--------------------+|Database......
  • 【研究生学习】Pytorch基本知识
    本篇博客记录一下Pytorch的基本知识,同时也通过各种实例来帮助理解如何使用PytorchPytorch中的张量Pytorch中的自动求导在目前的深度学习框架中,自动求导功能是最核心也是......
  • python apscheduler 定时任务的基本使用-4-cron触发器的使用
    pythonapscheduler定时任务的基本使用-4-cron触发器的使用1、前言cron触发器,当前时间与cron表达式匹配时,执行任务,等同于UNIX的cron。官网cron2、参数说明参数如下,除......
  • golang相关介绍
    前言:golang的语言介绍,发展介绍,相关网站正文:golang介绍Go语言(或Golang)起源于2007年,并在2009年正式对外发布。是由Google公司开发的一种静态强类型、编译型、并发......
  • Markdown基本语法指北
    \(\color{red}Markdown\)一级标题二级标题三级标题四级标题五级标题六级标题分割线加粗\(**加粗文字**\)$$中可放\(\color{red}\LaTeX\)公式,详询请看LaTeX......