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. 实训篇-Html-多媒体标签

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. React中受控组件和非受控组件

    一.受控组件 受控组件,简单来讲,就是受我们控制的组件,组件的状态全程响应外部数据 举个简单的例子: class TestComponent extends React.Component { con ...

  3. 一不小心,它成为了 GitHub Alibaba Group 下 Star 最多的开源项目

    简介: 随着微服务的流行,应用更加轻量和高效,但是带来的困境是线上问题排查越来越复杂困难.传统的 Java 排查问题,需要重启应用再进行调试,但是重启应用之后现场会丢失,问题难以复现. 来源 | 阿里 ...

  4. 庖丁解牛|图解 MySQL 8.0 优化器查询转换篇

    ​简介: 本篇介绍子查询.分析表和JOIN的复杂转换过程 一  背景和架构 在<庖丁解牛-图解MySQL 8.0优化器查询解析篇>一文中我们重点介绍了MySQL最新版本8.0.25关于SQ ...

  5. [FAQ] CodeMirror5, CodeMirror6 EditorView 获取输入值和设置值的方式

      获取值: // CodeMirror5 cm.getValue() 改为使用 // CodeMirror6 cm.state.doc.toString() 设置值: // CodeMirror5 ...

  6. [Go] go build 和 go install 的区别

    $ go build 源文件及其包依赖 编译成二进制. install 不仅执行build过程 而且会把编译的二进制放到 $GOPATH/bin/,包放到 $GOPATH/pkg/ Link:http ...

  7. dotnet SemanticKernel 入门 将技能导入框架

    在上一篇博客中和大家简单介绍了 SemanticKernel 里的技能概念,接下来咱准备将 技能 导入到 SemanticKernel 框架里面,进行一个管道式调用 本文属于 SemanticKern ...

  8. 02. rails安装

    rails安装 ruby 1.8.6 对应的rails是2.3.2 Ruby 1.8.7 或 1.9.2 对应的rails 2.3.x ruby1.9.3,对应的rails是3.2.12, ruby2 ...

  9. 80x86汇编—汇编程序基本框架

    文章目录 First Program 指令系统 伪指令 数值表达式 程序框架解释 int 21 中断 通过一个基本框架解释各个指令和用处,方便复习.所以我认为最好的学习顺序就是先看一段完整的汇编代码程 ...

  10. 5GC 系统架构

    目录 文章目录 目录 前文列表 4G/5G 核心网对比 4G/5G 核心网融合架构 5GC 架构 AMF 功能 SMF 功能 NSSF 功能 UPF 功能 AF.PCF & NEF 功能 BS ...