Bo's Oracle Station

查看: 692|回复: 0

ANSIBLE11

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-8-12 20:33:55 | 显示全部楼层 |阅读模式
  1. ---
  2. - name: Mariadb Server is Running
  3.   hosts: dbgroup
  4.   vars:
  5.     v_mysql:
  6.       - mariadb-server
  7.       - python3-PyMySQL
  8.   tasks:
  9.   - name: Mariadb Package are Installed
  10.     yum:
  11.       name: "{{ item }}"
  12.       state: latest
  13.     loop: "{{ v_mysql }}"

  14.   - name: Start Database Running
  15.     service:
  16.       name: mariadb
  17.       state: started
  18.       enabled: yes

  19. - name: Mariadb Server is Running
  20.   hosts: classroom.example.com
  21.   vars:
  22.     v_mysql2:
  23.       - mariadb-server
  24.       - python3-PyMySQL
  25.   tasks:
  26.   - name: Mariadb Package are Installed
  27.     yum:
  28.       name: "{{ item }}"
  29.       state: present
  30.     loop: "{{ v_mysql2 }}"
  31.     when: ansible_distribution == "RedHat"
复制代码
下面这个有很像考题:

  1. ---
  2. - name: Copy httpd Temp Config
  3.   hosts: server2.example.com
  4.   tasks:
  5.   - name: Copy httpd  Temp
  6.     copy:
  7.       src: "/home/student/ansible/v6.d/vhosts.conf"
  8.       dest: "/etc/httpd/conf.d/vhosts.conf"
  9.     notify:
  10.       - h_configfile

  11.   - name: Create Vhosts Dir
  12.     file:
  13.       dest: "/var/www/html/server2"
  14.       state: directory
  15.     notify:
  16.       - h_direxists_server2

  17.   - name: Create Vhosts Dir2
  18.     file:
  19.       dest: /var/www/html/www2
  20.       state: directory
  21.     notify:
  22.       - h_direxists_www2

  23.   handlers:
  24.   - name: h_direxists_server2
  25.     copy:
  26.       content: "Welcome to server2.example.com."
  27.       dest: "/var/www/html/server2/index.html"

  28.   - name: h_direxists_www2
  29.     copy:
  30.       content: "Welcome to www2.example.com."
  31.       dest: "/var/www/html/www2/index.html"

  32.   - name: h_configfile
  33.     service:
  34.       name: httpd
  35.       state: restarted

  36. - name: Test Vhosts
  37.   hosts: localhost
  38.   vars:
  39.     v_url:
  40.       - server2.example.com
  41.       - www2.example.com
  42.   tasks:
  43.   - name: Connect
  44.     uri:
  45.       url: "http://{{ item }}"
  46.       return_content: yes
  47.       status_code: 200
  48.     loop:
  49.       "{{ v_url }}"
  50.     register: v_result

  51.   - name: Show
  52.     debug:
  53. #      var: v_result
  54.       msg:
  55.         The result for "{{ item.content }}."
  56.     loop:
  57.       "{{ v_result.results }}"


复制代码
v6.d.zip (2.52 KB, 下载次数: 28)
回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-9 13:19 , Processed in 0.034072 second(s), 27 queries .

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