使用Ansible自动化部署FreeRadius+DaloRadius+PHP+Mariadb
---
- hosts: freeradius
become: yes
tasks:
- name: 安装必要的软件包
apt:
name: "{{ item }}"
state: present
with_items:
- freeradius
- freeradius-mysql
- libmysqlclient-dev
- php-pear
- php-dev
- php-mysql
- php-cli
- php-fpm
- mariadb-server
when: ansible_os_family == "Debian"
- name: 配置FreeRadius
copy:
src: etc/raddb/radiusd.conf.in
dest: /etc/raddb/radiusd.conf
owner: root
group: root
mode: 0600
- name: 配置PHP
copy:
src: etc/php/php.ini
dest: /etc/php/7.0/cli/php.ini
owner: root
group: root
mode: 0644
- name: 配置MariaDB
shell: mysql_secure_installation
when: ansible_os_family == "Debian"
- name: 创建FreeRadius数据库和用户
mysql_user:
login_host: localhost
user: root
password: "{{ mysql_root_password }}"
name: "{{ freeradius_db_user }}"
host: localhost
password: "{{ freeradius_db_password }}"
priv: "{{ freeradius_db_name }}.*:ALL"
- name: 创建FreeRadius数据库
mysql_db:
login_host: localhost
user: root
password: "{{ mysql_root_password }}"
name: "{{ freeradius_db_name }}"
state: present
- name: 导入FreeRadius数据库架构和预配置查询
shell: rademysql -f /etc/raddb/sql/mysql/schema.sql -f /etc/raddb/sql/mysql/nas.sql -f /etc/raddb/sql/mysql/counter.sql -f /etc/raddb/sql/mysql/policy.sql -f /etc/raddb/sql/mysql/accounting.sql -f /etc/raddb/sql/mysql/wimax.sql -f /etc/raddb/sql/mysql/dialup.sql -f /etc/raddb/sql/mysql/radius_db.sql -u "{{ freeradius_db_user }}" -p "{{ freeradius_db_password }}" "{{ freeradius_db_name }}"
args:
chdir: /etc/raddb
- name: 启动MariaDB服务
service:
name: mariadb
state: started
when: ansible_os_family == "Debian"
- name: 启动PHP-FPM服务
service:
name: php7.0-fpm
state: started
when: ansible_os_family == "Debian"
- name: 启动FreeRADIUS服务
service:
name: freeradius
state: started
这个代码实例展示了如何使用Ansible自动化部署FreeRADIUS服务,包括安装必要的软件包、配置FreeRADIUS、配置PHP和MariaDB,以及创建数据库和用户。同时,代码中包含了条件判断,以确保在正确的操作系统上执行相应的任务。
评论已关闭