ansible-playbook初始化系统

1,实验环境快速部署

[root@aghj-11 init_C]# tree
.
├── hosts
├── hosts.j2
└── inic.yaml
[root@aghj-11 init_C]# cat hosts
[initC]
10.1.1.38 mq_name=node1
10.1.1.39 mq_name=node2
10.1.1.40 mq_name=node3
[root@aghj-11 init_C]# cat hosts.j2 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
{% for host in groups['initC'] %}
{{ hostvars[host].inventory_hostname }} {{ hostvars[host].mq_name }}
{% endfor %} 
[root@aghj-11 init_C]# cat inic.yaml 
---
- hosts: initC
  vars:
  remote_user: root
  gather_facts: false

  tasks:
  - name: 关闭防火墙
    service: name=firewalld state=stopped enabled=no

  - name: 关闭selinux
    lineinfile:
      dest: /etc/selinux/config
      regexp: "^SELINUX="
      line: "SELINUX=disabled"
  
  - name: 即时生效
    shell: setenforce 0 ; swapoff -a

  - name: 关闭swap
    lineinfile:
      dest: /etc/fstab
      regexp: ".*swap"
      line: ""

  - name: 拷贝时区
    copy: src=/usr/share/zoneinfo/Asia/Shanghai dest=/etc/localtime

  - name: 添加hosts
    template: src=hosts.j2 dest=/etc/hosts 

  - name: 删除老yum源
    shell: rm -rf /etc/yum.repos.d

  - name: 添加新yum源 
    copy: src=/etc/yum.repos.d/ dest=/etc/yum.repos.d/

  - name: 更新源
    shell: yum repolist
  
  - name: 安装lrzsz
    yum: name=lrzsz 

  - name: 安装net-tools
    yum: name=net-tools 

  - name: 安装wget
    yum: name=wget 

  - name: 安装gcc
    yum: name=gcc 

  - name: 安装开发者工具库
    yum: name='@Development Tools'

  - name: 更改内核最大连接数
    copy: src=/etc/security/limits.conf dest=/etc/security/limits.conf 

  - name: 设置java连接数
    shell: sed -i '$a vm.max_map_count=262144' /etc/sysctl.conf ; sysctl -p
  
  - name: 重启
    shell: reboot

 

你可能感兴趣的:(ansible)