Ansible

Ansible

Ansible作为一个管理工具,可以同时在多台主机进行一些功能如ping copy shell

以下是一下基本操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
首先yum install -y ansible

在/etc/ansible/hosts里面配置主机

[webserver]
hosts1 ansible_ssh_user='' ansible_ssh_pass=''
hosts2 ansible_ssh_user='' ansible_ssh_pass=''
hosts3 ansible_ssh_user='' ansible_ssh_pass=''

接着直接调用模块
ansible webserver -m ping
ansible webserver -m copy -a 'src= dest='

可以在其他文件找主机
ansible -i hostlist webserver -m ping
ansible -i hostlist webserver -m copy -a 'src= dest='

然后是第二个模块user

1
2
3
4
5
6
增加用户
ansible webserver -m user -a 'name=flp state=present'

增加密码
echo "casio233." | openssl passwd -1 stdin
ansible webserver -m user -a 'name=flp password=""'

yum板块

1
2
3
4
5
6
7
8
下载
ansible webserver -m yum -a "name=tree state=latest"

卸载
ansible webserver -m yum -a "name=tree state=absent"

启动服务
ansible webserver -m service -a 'name=httpd state=started'

创建文件

1
ansible webserver -m file -a 'path=/tmp/44 mode=771 state=touch/directory'

接下写常见的了

1
2
3
4
5
可以输出管理的主机名 很方便
ansible webserver -m shell -a 'hostname' -o

可以不用前面那个麻烦的下载方式用shell
ansible webserver -m shell -a 'yum install -y httpd' -o

Ansible
http://example.com/2024/04/07/Ansible/
作者
Jack Asher
发布于
2024年4月7日
许可协议