ansbile自动安装配置samba服务器

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值