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