ansible -m shell -a "echo "user1:123" | chpasswd" all
时间: 2023-11-13 14:32:35 浏览: 87
这个 Ansible 命令是在所有主机上执行一个 shell 命令,将 "user1" 用户的密码修改为 "123"。
具体来说,"-m shell" 参数指定使用 shell 模块来执行命令,"-a" 参数后面跟着要执行的命令,即将 "user1:123" 通过管道输入到 "chpasswd" 命令中。"all" 指定要在所有主机上执行该命令。
需要注意的是,这个命令需要在具有 root 权限的用户下执行,否则修改密码的操作可能会失败。另外,明文存储密码是不安全的,建议使用其他更安全的方式来管理密码。
相关问题
使用ansible 写出vsftpd
使用ansible编写vsftpd的配置文件和服务的安装和启动脚本:
1. 编写vsftpd的配置文件
```
# /etc/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
chroot_list_file=/etc/vsftpd.chroot_list
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
```
2. 编写安装和启动脚本
```
---
- hosts: ftp_servers
become: true
vars:
vsftpd_conf_path: /etc/vsftpd.conf
vsftpd_service_name: vsftpd
tasks:
- name: Install vsftpd package
apt:
name: vsftpd
state: present
- name: Create vsftpd user
user:
name: ftpuser
shell: /sbin/nologin
system: yes
- name: Create vsftpd directory
file:
path: /home/ftpuser
state: directory
owner: ftpuser
group: ftpuser
mode: 0755
- name: Set vsftpd password
shell: "echo 'ftpuser:password' | chpasswd"
- name: Create vsftpd chroot list file
copy:
dest: /etc/vsftpd.chroot_list
content: |
ftpuser
- name: Copy vsftpd configuration file
copy:
src: files/vsftpd.conf
dest: "{{ vsftpd_conf_path }}"
owner: root
group: root
mode: 0644
- name: Restart vsftpd service
service:
name: "{{ vsftpd_service_name }}"
state: restarted
```
注意,上面的脚本中的`ftp_servers`是指定的主机组名称,需要在Ansible的inventory文件中定义。另外,需要将vsftpd的配置文件`vsftpd.conf`和密码文件`vsftpd.chroot_list`放在指定的`files`目录中。
阅读全文
相关推荐

















