查看“RHCE8.0实训:管理变量”的源代码
←
RHCE8.0实训:管理变量
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==实训目的== *在playbook中定义变量。 *创建使用定义的变量的任务。 ==实训步骤== ===配置文件=== 在当前目录(/root)下新建目录0528 mkdir 0528 cd 0528 ====ansible.cfg==== vi ansible.cfg <nowiki>[defaults] inventory = /root/0528/hosts host_key_checking = False</nowiki> ====inventory文件==== vi hosts <nowiki> [master] localhost ansible_connection=local ansible_ssh_user=root 10.0.0.30 ansible_ssh_user=root [slave] 10.0.0.32 ansible_ssh_user=root </nowiki> 验证:列出配置过的主机列表 ansible all --list-host <nowiki>hosts (3): localhost 10.0.0.30 10.0.0.32</nowiki> ===编写play=== [root@localhost ansible]# mkdir data-variables [root@localhost ansible]# cd data-variables vi playbook.yml <nowiki> --- - name: Deploy and start Apache HTTPD service hosts: slave vars: web_pkg: httpd firewall_pkg: firewalld web_service: httpd firewall_service: firewalld python_pkg: python3-PyMySQL rule: http tasks: - name: Required pachages are installed and up to date yum: name: - "{{ web_pkg }}" - "{{ firewall_pkg }}" state: latest - name: The {{ firewall_service }} service is started and enabled service: name: "{{ firewall_service }}" enabled: true state: started - name: The {{ web_service }} service is started and enabled service: name: "{{ web_service }}" enabled: true state: started - name: Web content is in place copy: content: "Example web content" dest: /var/www/html/index.html - name: The firewall port for {{ rule }} is open firewalld: service: "{{ rule }}" permanent: true immediate: true state: enabled - name: Verify the Apache service hosts: localhost become: false tasks: - name: Ensure the webserver is reachable uri: url: http://localhost status_code: 200 </nowiki> ===语法检查=== [root@localhost data-variables]# ansible-playbook --syntax-check playbook.yml <nowiki>[DEPRECATION WARNING]: The firewalld module has been moved to the ansible.posix collection. This feature will be removed from community.general in version 2.0.0. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. playbook: playbook.yml</nowiki> ===执行play=== [root@localhost data-variables]# ansible-playbook playbook.yml <nowiki>[DEPRECATION WARNING]: The firewalld module has been moved to the ansible.posix collection. This feature will be removed from community.general in version 2.0.0. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. PLAY [Deploy and start Apache HTTPD service] *********************************************************************** TASK [Gathering Facts] ********************************************************************************************* ok: [localhost] ok: [10.0.0.30] TASK [Required pachages are installed and up to date] ************************************************************** ok: [localhost] ok: [10.0.0.30] TASK [The firewalld service is started and enabled] **************************************************************** ok: [localhost] ok: [10.0.0.30] </nowiki>
返回至
RHCE8.0实训:管理变量
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息