基于ansible自动化部署ftp服务

Ansible部署FTP服务

基础环境配置就不过多赘述了

  • 配置主机名、主机解析、免密访问、ansible下载、配置ansible主机、防火墙、selinux、配置centos2009镜像为仓库源、配置ftp远程仓库:可参考博文

节点信息如下:

主机名 IP
ansible 192.168.200.75
node 192.168.200.76

开始编写ansible文件

powershell 复制代码
[root@ansible ~]# mkdir ansible_ftp
[root@ansible ~]# cd ansible_ftp/
[root@ansible ansible_ftp]# cat install_ftp.yaml
---
- hosts: node1
  remote_user: root
  tasks:

    - name: Selinux Config Setenforce
      shell: getenforce
      register: info

    - name: when_Selinux
      shell: setenforce 0
      when: info['stdout'] == 'Enforcing'

    - name: move repos
      shell: mv /etc/yum.repos.d/* /media

    - name: create ftp.repo
      copy: src=local.repo dest=/etc/yum.repos.d/

    - name: install ftp-server package
      yum: name=vsftpd state=present

    - name: start vsftpd
      service: name=vsftpd state=started

[root@ansible ansible_ftp]# cat local.repo
[centos]
name=centos
baseurl=ftp://ansible/centos/
gpgcheck=0
enabled=1

检查剧本并执行

powershell 复制代码
[root@ansible ansible_ftp]# ansible-playbook  --syntax-check install_ftp.yaml

playbook: install_ftp.yaml
[root@ansible ansible_ftp]# ansible-playbook install_ftp.yaml

PLAY [node1] ***********************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.200.76]

TASK [Selinux Config Setenforce] ***************************************************************************************
changed: [192.168.200.76]

TASK [when_Selinux] ****************************************************************************************************
skipping: [192.168.200.76]

TASK [move repos] ******************************************************************************************************
changed: [192.168.200.76]

TASK [create ftp.repo] *************************************************************************************************
changed: [192.168.200.76]

TASK [install ftp-server package] **************************************************************************************
changed: [192.168.200.76]

TASK [start vsftpd] ****************************************************************************************************
changed: [192.168.200.76]

PLAY RECAP *************************************************************************************************************
192.168.200.76             : ok=6    changed=5    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

[root@ansible ansible_ftp]#

验证

powershell 复制代码
[root@node1 ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-05-03 03:07:26 EDT; 31s ago
  Process: 2718 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 2719 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─2719 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

May 03 03:07:25 node1 systemd[1]: Starting Vsftpd ftp daemon...
May 03 03:07:26 node1 systemd[1]: Started Vsftpd ftp daemon.
[root@node1 ~]#
相关推荐
SelectDB4 小时前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220702 天前
如何搭建本地yum源(上)
运维
大树885 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠5 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质5 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
Inhand陈工5 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
酣大智5 天前
ARP代理--工作原理
运维·网络·arp·arp代理
shushangyun_5 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
施努卡机器视觉5 天前
SNK施努卡侧滑门锁上滑轮总成自动化装配线,从零件到组件,全流程精密制造方案
运维·自动化·制造