ansible自动化部署web服务

项目(一)
任务一:安装httpd,firewalld软件包
任务二:创建网站资源文件
任务三:启动httpd,firewalld
任务四:添加防火墙规则
项目(二)
uri测试
通过debug捕获打印测试结果

1.安装部署ansible
2.vim ./ansible.cfg
[defaults]
Inventory=./inventory
Remote_user=root
Host_key_checking=False
3.vim inventory
node1
node2
4.和受控主机进行免密验证
ssh-keygen -t rsa
ssh-copy-id -i root@node1
ssh-copy-id -i root@node2
ssh root@node1
5.剧本
vim playbook.yml

  • name: play0
    hosts: node1
    tasks:
  • name: task1
    mount:
    path: /mnt
    src: /dev/sr0
    fstype: iso9660
    state: present
  • name: task1
    mount:
    path: /mnt
    src: /dev/sr0
    fstype:
    state: present
    • name: tasks2
      yum_repository:
      name: BaseOS
      description: EPEL YUM repo
      file: base
      baseurl: file:///mnt/BaseOS
      gpgcheck: no
    • name: tasks2
      yum_repository:
      name: BaseOS
      description: EPEL YUM repo
      file: base
      baseurl: file:///mnt/BaseOS
      gpgcheck: no
    • name: task3
      yum:
      name:
      • httpd
      • firewalld
        state: present
    • name: task4
      copy:
      dest: /var/www/html/index.html
      content: >
      This is www
    • name: task5
      service:
      name: httpd
      state: started
      enabled: ture
    • name: taks6
      firewalld:
      port: 80/tcp
      zone: public
      permanent: yes
      immediate: yes
      state: enabled
  • name: play1
    hosts: node2
    tasks:
    • name: task7
      uri:
      url: https://node1
      return_content: yes
      status_vode: 200
      register: result
    • name: task8
      debug:
      msg: “{{ result }}”
    • name: task9
      command:
      echo “{{ result }}”
      6.测试
      ansible-playbook -C playbook.yml

你可能感兴趣的:(ansible,自动化,linux)