[root@ansible ~]
[webservers]
10.0.0.150 ansible_connection=local
10.0.0.160
[root@ansible html]
mkdir: created directory '/data/ansible'
mkdir: created directory '/data/ansible/roles'
mkdir: created directory '/data/ansible/roles/httpd'
mkdir: created directory '/data/ansible/roles/httpd/tasks'
mkdir: created directory '/data/ansible/roles/httpd/handlers'
mkdir: created directory '/data/ansible/roles/httpd/files'
[root@ansible html]
[root@ansible httpd]
- include: group.yml
- include: user.yml
- include: install.yml
- include: config.yml
- include: index.yml
- include: service.yml
[root@ansible httpd]
- name: create apache group
group: name=apache system=yes gid=80
[root@ansible httpd]
- name: create apache user
user: name=apache system=yes shell=/sbin/nologin home=/var/www/ uid=80 group=apache
[root@ansible httpd]
- name: install httpd package
yum: name=httpd
[root@ansible httpd]
- name: config file
copy: src=httpd.conf dest=/etc/httpd/conf/ backup=yes
notify: restart
[root@ansible httpd]
- name: index.html
copy: content='{{ ansible_hostname }}\n' dest=/var/www/html/index.html
[root@ansible httpd]
- name: start httpd service
service: name=httpd state=started enabled=yes
[root@ansible httpd]
- name: restart
service: name=httpd state=restarted
[root@ansible httpd]
files/httpd.conf
[root@ansible httpd]
/data/ansible/roles/httpd/
├── files
│ └── httpd.conf
├── handlers
│ └── main.yml
└── tasks
├── config.yml
├── group.yml
├── index.yml
├── install.yml
├── main.yml
├── service.yml
└── user.yml
3 directories, 9 files
[root@ansible ~]
- hosts: webservers
remote_user: root
roles:
- httpd
[root@ansible ~]
[root@ansible ~]
ansible
[root@ansible ~]
node1
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具