这是一个简单的Ansible playbook,可以在Rhel / CentOS 7服务器上搭建Apache Web服务器 :
[root@controller playbooks]# pwd /root/playbooks [root@controller playbooks]# cat httpd.yaml -- - name: This sets up an httpd webserver hosts: ansibleclient01.local tasks: - name: Install apache packages yum: name: httpd state: present - name: ensure httpd is running service: name: httpd state: started - name: Open port 80 for http access firewalld: service: http permanent: true state: enabled - name: Restart the firewalld service to load in the firewall changes service: name: firewalld state: restarted
下面是上述yaml语法所显示内容的分解。最顶层是一个单项列表。此列表项包含一个具有3个键值对的哈希。第一个键的值是字符串类型。但是,第三个键(任务)包含4个项目的列表。这些列表项中的每一项都包含一个散列。每个散列由2个键值对组成。
现在让我们运行这个剧本:
[root@controller playbooks]# pwd /root/playbooks [root@controller playbooks]# ls httpd.yaml $ ansible-playbook httpd.yml
我们可以通过在Web浏览器中打开到http://ansibleclient01.local来测试是否有效。
日期:2020-07-07 20:57:25 来源:oir作者:oir