Bo's Oracle Station

查看: 740|回复: 0

ANSIBLE3

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-8-5 21:14:06 | 显示全部楼层 |阅读模式
独立命令的测试:
  1. [student@classroom ansible]$ ansible webgroup  -m shell   -a 'rm -f  /etc/httpd/conf.d/vhosts.conf'
复制代码




剧本的测试脚本:
  1. ---
  2. - name: 测试
  3.   hosts: all
  4.   tasks:
  5.   - name: 任务1
  6.     debug:
  7.       msg: |
  8.         "{{ inventory_hostname }}"
复制代码


  1. ---
  2. - name: Play to Setup Webservers
  3.   hosts: webgroup
  4.   tasks:
  5.   - name: Yum Install:httpd
  6.     yum:
  7.       name: httpd
  8.       state: latest

  9.   - name: Running:httpd Service
  10.     service:
  11.       name: httpd
  12.       state: started
  13.       enabled: yes

  14.   - name: Create Homepages
  15.     lineinfile:
  16.       path: /var/www/html/index.html
  17.       line: "welcome to {{ inventory_hostname }}\n<a href="http://{{ inventory_hostname }}/again.html">AGAIN LINK</a>"
  18.       create: yes

  19.   - name: Create Content
  20.     copy:
  21.       content: "Welcome to {{ inventory_hostname }} again"
  22.       dest: /var/www/html/again.html
  23.       follow: yes

  24.   - name: Firewall
  25.     firewalld:
  26.       service: http
  27.       permanent: yes
  28.       state: enabled
  29.       immediate: yes

  30. - name: Test Homepage
  31.   hosts: localhost
  32.   vars:
  33.     v_url:
  34.      - http://server1.example.com
  35.      - http://server2.example.com
  36.   tags:
  37.   - tag1

  38.   tasks:
  39.   - name: Connect to the webservers
  40.     uri:
  41.       url: "{{ item }}"
  42.       # validate_certs: no
  43.       # force_basic_auth: no
  44.       # user: testuser1
  45.       # password: redhat123
  46.       return_content: yes
  47.       status_code: 200
  48.     register: v_return
  49.     loop:
  50.       "{{ v_url }}"

  51.   - name: debug   
  52.     debug:
  53.       var: v_return

  54.       # msg:
  55.       #  "{{ v_return}}"
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-20 12:31 , Processed in 0.038067 second(s), 24 queries .

快速回复 返回顶部 返回列表