首页 > 系统相关 >centos7离线部署ansible并通过ansible批量修改用户密码

centos7离线部署ansible并通过ansible批量修改用户密码

时间:2023-03-06 10:13:18浏览次数:45  
标签:portable python app 离线 192.168 centos7 etc ansible

centos7离线部署ansible并通过ansible批量修改用户密码

找台可以联网的机器下载好程序包,上传到对应主机

mkdir /app/ansible -p
#下载bzip2
yum install -y bzip2 --downloadonly --downloaddir=/app/ansible
cd ansible
#支持python2,根据系统的python版本来选择
wget https://github.com/ownport/portable-ansible/releases/download/v0.4.0/portable-ansible-v0.4.0-py2.tar.bz2 
#支持python3
wget https://github.com/ownport/portable-ansible/releases/download/v0.4.0/portable-ansible-v0.4.0-py3.tar.bz2

安装并解压ansible二进制包,注意这里解压后,目录层级不要搞错了

cd /app/ansible
#安装bzip2
yum install bzip2-1.0.6-13.el7.x86_64.rpm -y
#解压portable-ansible
tar xjf portable-ansible-v0.4.0-py2.tar.bz2
#使用软链创建ansible-playbook
ln -s ansible/ ansible-playbook

在/etc/profile末尾追加两行内容

alias ansible='python /app/ansible/ansible'
alias ansible-playbook='python /app/ansible/ansible-playbook'

添加好后执行以下文件使环境变量生效

source /etc/profile

检查ansible是否可用

ansible --version #执行该命令验证是否正常返回版本号
ansible 2.9.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/app/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /app/ansible/ansible/ansible
  executable location = /app/ansible/ansible
  python version = 2.7.5 (default, Oct 14 2020, 14:45:30) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

编辑配置文件/etc/ansible/ansible.cfg

vi /etc/ansible/ansible.cfg

[defaults]
inventory=./inventory
host_key_checking = False

编辑并创建/etc/ansible/inventory文件,参考示例如下

[test-host]
192.168.108.1
192.168.108.2
192.168.108.3
192.168.108.4
192.168.108.7
192.168.108.8
192.168.108.18
192.168.108.19
192.168.108.23
192.168.108.24
192.168.108.25



[test-host:vars]
ansible_ssh_pass="nN@xxxxxx"

执行以下命令批量修改密码

示例:
ansible test-host -m shell -a "echo 'nN@123456' | passwd --stdin 用户名
ansible test-host -m shell -a "echo 'nN@456789' | passwd --stdin root

标签:portable,python,app,离线,192.168,centos7,etc,ansible
From: https://www.cnblogs.com/caidingyu/p/17182768.html

相关文章

  • 离线yum实施部署
    明确版本后在网上找到对应的镜像全量包http://mirrors.huaweicloud.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.isocat/etc/rel将镜像上传至服务器上面......
  • centos7在线扩容根分区LVM
    背景:现已有lvm根分区,不能满足业务需求,在业务不下线的情况下对/分区扩容思路:创建新分区=>创建物理卷=>加入卷组=>扩容1、找到要扩容的分区2、找到新添加的磁盘......
  • CentOS7配置iSCSI共享-tgtd
    作者:独笔孤行官网:​​ ​​http://anyamaze.com​​公众号:云实战前言iSCSI又称为IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术,iSCSI利用了TCP/IP的port860和3260......
  • centos7升级 cmake
    一、删除旧版本cmake升级到最新版本前应事先删除旧版本内核。cmake-versionyumremove-ycmake二、安装需要的模块yuminstall-ylibxml2libxml2-develbzip2bzip2-d......
  • centos7.9编译安装libzip-1.9.2 和 cmake 3.23.0
    centos7.9编译安装libzip-1.9.2在编译安装php时系统会报configure:error:Packagerequirements(libzip>=0.11libzip!=1.3.1libzip!=…这是因为libzip版本过......
  • 【Dockerfile】nvm-git-node-centos7镜像
    #依赖centos环境FROMcentos:7#安装vim、git和nvm环境RUNyuminstall-ywget\&&mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.rep......
  • CentOS7 安装Chrome
    转载自:https://blog.csdn.net/ling1998/article/details/1239517261、权限若不是root权限,需要在root下执行为用户授权命令,我直接使用root登录2、下载[root@localhosts......
  • Linux离线安装mysql5.7
    下载mysql:https://dev.mysql.com/downloads/mysql/5.7.html#downloads  切换到root用户解压mysql压缩包tar-zxvfmysql-5.7.24-linux-glibc2.12-x86_64.tar.......
  • docker学习笔记1(在线安装及离线安装)
    Centos7安装docker引擎官方安装文档https://docs.docker.com/engine/install/centos/#install-using-the-repositoryDocker分两个大版本,一个是CE,一个是EE。CE为社区版,......
  • PHP8安装(centos7环境)
    一、事先安装的模块yuminstall-ybzip2-devellibcurl-devellibxml2-develsqlite-develonigurumaoniguruma-devellibxml2libxml2-develbzip2bzip2-devellibcurl......