ansible配置步骤

1.创建用户

2.用户提权

3.用户免密

4.cp ansible配置文件

5.配置主机清单

6.修改ansible 用户路径下的配置文件

1.创建用户(都要做)

[root@localhost ~]# useradd  hum
[root@localhost ~]# passwd hum
Changing password for user hum.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

2.用户提权(都要做)

[root@localhost ~]# cat /etc/sudoers.d/hum
hum ALL=(ALL) NOPASSWD:ALL

3.用户免密

[root@localhost ~]# su hum
[hum@localhost root]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hum/.ssh/id_rsa):
Created directory '/home/hum/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hum/.ssh/id_rsa.
Your public key has been saved in /home/hum/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:emW7KWD/2eSSFA1IRpmZMXEBt4g8bkr1A+nBN/vGQWE hum@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| oOXE. |
| o +**.o |
| X + oo |
| + * +. . |
| . + S +. |
| . oo. *.o |
| ...o..=.. |
| .o.oB |
| o=.o |
+----[SHA256]-----+
[hum@localhost ~]$ ll -a
total 12
drwx------. 4 hum hum 90 Dec 6 09:25 .
drwxr-xr-x. 4 root root 28 Dec 5 16:05 ..
-rw-r--r--. 1 hum hum 18 Dec 4 2020 .bash_logout
-rw-r--r--. 1 hum hum 141 Dec 4 2020 .bash_profile
-rw-r--r--. 1 hum hum 376 Dec 4 2020 .bashrc
drwxr-xr-x. 4 hum hum 39 Nov 19 21:56 .mozilla
drwx------. 2 hum hum 38 Dec 6 09:25 .ssh
[hum@localhost ~]$ ssh-copy-id hum@192.168.10.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hum/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is SHA256:LC3ur7vjJjDH/59gWsQu/kreK4GdZwhlh+M3SJ6/S+s.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hum@192.168.10.20's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'hum@192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.

验证:

#远程连接不用输密码
[hum@control root]$ ssh hum@node1
Activate the web console with: systemctl enable --now cockpit.socket This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register Last login: Wed Dec 6 09:35:43 2023 from 192.168.10.10
[hum@node1 ~]$ exit
logout
Connection to node1 closed. #sudo 命令不用输入root密码
[hum@control root]$ ls
ls: cannot open directory '.': Permission denied
[hum@control root]$ sudo ls
anaconda-ks.cfg Music
Desktop Pictures
Documents Public
Downloads Templates
initial-setup-ks.cfg Videos

4.cp ansible配置文件

[hum@control ~]$ cp -r /etc/ansible/ .
[hum@control ~]$ ll
total 0
drwxr-xr-x. 3 hum hum 51 Dec 6 09:41 ansible

5.配置主机清单

[hum@control ansible]$ vim hosts
[hum@control ansible]$ sort hosts
node1

6.修改ansible 用户路径下的配置文件

[hum@control ansible]$ cat ansible.cfg
[defaults]
inventory = /home/hum/ansible/hosts#定义默认使用的主机清单
ask_pass = false#ansible在操作远程主机时,获取远程主机上的用户身份,是否提示密码验证,默认为True。如果使用密钥认证的话,建议将其设置为False
remote_user = hum#用户在操作远程主机时,使用远程主机上的哪个身份,默认是root
log_path = /var/log/ansible.log [privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False [ssh_connection]
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
host_key_checking = false

实验成功:

[hum@control ansible]$ ansible node1 -m shell -a  "whoami"
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting node1 | CHANGED | rc=0 >>
root

ansible搭建的更多相关文章

  1. 用Vagrant和Ansible搭建持续交付平台

    这是一个关于Vagrant的学习系列,包含如下文章: Vagrant入门 创建自己的Vagrant box 用Vagrant搭建Jenkins构建环境 用Vagrant和Ansible搭建持续交付平台 ...

  2. 【Linux运维】Centos7上借助ansible搭建LVS+Keepalived

    安装ansible 安装ansible: [root@localhost ~]# /etc/hosts 192.168.19.129 web129.yanglt.com web129 192.168. ...

  3. ansible搭建mysql主主模式

    ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)等优点,实现了批量系统配置.批量程序部署.批量运行命 ...

  4. Linux实战教学笔记25:自动化运维工具之ansible (一)

    第二十五节 ansible之文件的批量分发 标签(空格分隔): Linux实战教学笔记-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转 ...

  5. ssh密钥分发与ansible

    笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 当我们公司的服务器达到几十台或几百台或更高的时候,利用批量管理工具管理系统是我们要做的 常用的批量管理工具有ans ...

  6. 使用ansible安装lnmp

    主机互信 生成密钥对,并将公钥发送给其他需要操作的主机 ssh-keygen -t rsa cd /root/.ssh ssh-copy-id -i id_rsa.pub root@192.168.1 ...

  7. Ansible 利用playbook批量部署Nginx

    我这里直接部署的,环境已经搭建好,如果不知道的小伙伴可以看上一遍ansible搭建,都写好了,这里是根据前面环境部署的 192.168.30.21     ansible 192.168.30.25  ...

  8. 第二十六章 ansible主要模块介绍

    一.Ansible模块回顾 1.command模块 [root@m01 ~]# ansible web01 -m command -a 'free -m' 2.shell模块 #支持管道符这种特殊符号 ...

  9. 从0到1使用Kubernetes系列(三):使用Ansible安装Kubernetes集群

    前两期的文章介绍了Kubernetes基本概念和架构,用Kubeadm+Ansible搭建Kubernetes集群所需要的工具及其作用.本篇介绍怎么使用Ansible安装Kubernetes集群. 启 ...

  10. 【容器云】传统金融企业的 Docker 实践

    基于 Docker 的容器云-Padis 目前市面上基于容器云的产品有很多,对于平安而言,则是基于 Docker 的 Padis 平台.所谓 Padis,全称是 PingAn Distribution ...

随机推荐

  1. mmcls/mmdet模型部署至 TorchServe

    mmcls/mmdet模型部署至 TorchServe 官方教程:模型部署至 TorchServe - MMClassification 0.23.2 文档 接口说明: serve/inference ...

  2. SpringBoot使用Redis做缓存结合自带注解

    配置Spring Cache <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  3. 文本溢出显示省略号css

    项目中常常有这种需要我们对溢出文本进行"..."显示的操作,单行多行的情况都有(具体几行得看设计师心情了),这篇随笔是我个人对这种情况解决办法的归纳,欢迎各路英雄指教. 单行 语法 ...

  4. 推荐一波微软家的浏览器:EDGE

    前段时间英雄联盟(LOL)队伍 EDG 夺冠成为热门事件,上了各大热搜,即使大家不玩英雄联盟,相信也多多少少有听说相关信息吧! 今天我们的主角并不是 EDG,而是微软的新版浏览器 EDGE !!! 微 ...

  5. 力扣349(java&python)-两个数组的交集(简单)

    题目: 给定两个数组 nums1 和 nums2 ,返回 它们的交集 .输出结果中的每个元素一定是 唯一 的.我们可以 不考虑输出结果的顺序 . 示例 1: 输入:nums1 = [1,2,2,1], ...

  6. 庖丁解InnoDB之REDO LOG

    ​简介: 数据库故障恢复机制的前世今生一文中提到,今生磁盘数据库为了在保证数据库的原子性(A, Atomic) 和持久性(D, Durability)的同时,还能以灵活的刷盘策略来充分利用磁盘顺序写的 ...

  7. Prometheus+Grafana+alertmanager构建企业级监控系统(三)

    七.Prometheus监控扩展 7.1 Promethues 采集tomcat监控数据 tomcat_exporter地址:https://github.com/nlighten/tomcat_ex ...

  8. 一个可以输出当前移动设备机型(安卓,ios)系统版本的html页面

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 11.IO 流

    1.IO 流引入 概述:以应用程序为参照物,读取数据为输入流(Input),写数据为输出流(Output),大量输入输出数据简称 IO 流 原理: 2.IO 流的分类 读写的文件分类 二进制文件:打开 ...

  10. vim简明文档

    替换 替换当前行第一个 :s/vivian/sky/ 替换当前行第一个 vivian 为 sky 从当前行替换到最后一行 :%s/vivian/sky/g 替换所有行中 vivian 为 sky 查找 ...