奥德赛F9 发表于 2018-7-30 09:09:30

Ansible批量快速初始化新机器运维环境

---  
- hosts: new
  
remote_user: shanker
  
sudo: yes
  
gather_facts: true
  
vars:
  
    user: shanker
  
tasks:
  
- name: install provisioning tools, git and zsh dstat via yum
  
    yum: name={{ item }} state=installed
  
    when: ansible_os_family == "RedHat"
  
    with_items:
  
   - git
  
   - zsh
  
   - dstat
  
   - screen
  
- name: install provisioning tools, git and zsh dstat via apt-get
  
    apt: name={{ item }} state=installed
  
    when: ansible_os_family == "Debian"
  
    with_items:
  
   - git
  
   - zsh
  
   - dstat
  
   - screen
  

  
- name: install epel on centos6
  
    yum: name=http://archive.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm state=present
  
    when: ansible_os_family == "RedHat" and ansible_distribution_version|int <7
  
- name: install epel on centos7
  
    yum: name=https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm state=present
  
    when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=7
  

  
- name: install zsh as default shell
  
    script: /etc/ansible/setuptools/init_zsh.sh
  
- name: copy default screen file
  
    copy: src=/etc/ansible/setuptools/screenrc dest=/etc/screenrc mode=0644 owner=root group=root
  
- name: copy ssh provate key
  
    copy: src=/etc/ansible/setuptools/shanker.pri dest=/home/`user`/.ssh/ mode=0600 owner=`user` group=`user`
  
- name: copy ssh config
  
    copy: src=/etc/ansible/setuptools/config dest=/home/`user`/.ssh/ mode=0644 owner=`user` group=`user`
页: [1]
查看完整版本: Ansible批量快速初始化新机器运维环境