1. 当前目录准备预制配置文件:
template/smb.conf template/smbusers
2.配置playbook: smb.yaml
- hosts: local
user: root
vars:
- motd_warning: 'WARNING: Use by master ONLY'
tasks:
- name: ensure samba is at the latest version
yum: name=samba state=latest
- name: copy the samba config file
copy:
src: template/smb.conf
dest: /etc/samba/smb.conf
- name: copy the samba config file
copy:
src: template/smbusers
dest: /etc/samba/smbusers
notify:
- restart samba
- name: ensure samba is running
service: name=smb state=started
- name: add group
group: name=shujubu
- name: add user sj001
user: name=sj001 group=test shell=/sbin/nologin create_home=no
- name: set passwd to sj001
ansible.builtin.shell:
cmd: (echo 54321;echo 54321) | smbpasswd -a sj001
- name: add user jt001
user: name=jt001 group=test shell=/sbin/nologin create_home=no
- name: set passwd to jt001
ansible.builtin.shell:
cmd: (echo 12345;echo 12345) | smbpasswd -a jt001
- name: add user xt
user: name=xt group=test shell=/sbin/nologin create_home=no
- name: set passwd to xt
ansible.builtin.shell:
cmd: (echo 6789;echo 6789) | smbpasswd -a xt
handlers:
- name: restart samba
service: name=smb state=restarted
3.配置主机vi /etc/ansible/hosts
[local]
127.0.0.1 ansible_ssh_user=root ansible_ssh_pass=xtjk
4.执行:
ansible-playbook smb.yaml