With Ansible also has more than two years, before doing the initialization work is in the Kickstart configuration file with their shell script initialization system environment, now the operation and maintenance environment is different, the pre-system installation work to the IDC department to deal with, What I can do here is to initialize my favorite operations environment with a script. No ansible before using the shell can also achieve some of his functions, such as with the Ad-hoc scenario, based on the production environment of the Intranet SSH Key trust environment, write a For loop can also achieve simple function, but ansible never stop this role, Using his playbook will allow you to become an excellent OPS engineer and get the Oscar for Best System OPS Director award (if any).
The following playbook is what I do initialize the new machine operations environment, is a All-in-one file, and does not vars, tasks, templates, handlers these separate write. (The usual, it can be downloaded on my github.) )
$ cat Provision.yml
---
-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
-Htop
-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
-Htop
-screen
-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/myprivate.pem dest=/home/{{user}}/.ssh/mode=0600 Owner={{user}} Group={{user}}
Hosts:new, new is a group defined in/etc/ansible/hosts, here you can define casually, the format is such that the brackets inside the group name, and then the following is the machine name:
[New]
Ukcent1
Ukcent2
Remote_user:shanker refers to the user name of the remote execution playbook.
Sudo:yes, is to run Shanker in the form of sudo to perform some commands that require superuser privileges.
Gather_facts:true, is to let ansible charge system environment variable information, for the following judgment system is redhead or Debian pave.
VARs
User:shanker, is the user this variable value is Shanker, in the following copy SSH key to the home directory need to use.
Tasks below are the series of commands that will be executed:
The upper part of the installation system software this piece uses the Ansible loop and the conditionals syntax
{
For details, refer to the official documentation:
Http://docs.ansible.com/ansible/playbooks_loops.html
Http://docs.ansible.com/ansible/playbooks_conditionals.html
}
Judging if the system's family is the Redhat series to install the software with the Yum module, if the Debian series is installed with the Apt-get, and With_items can realize the need to install those software, you can expand their capacity.
Then the following scrip module, tell Ansible on the remote machine to execute my initialization zsh script, has become accustomed to the powerful zsh, this must be added.
The following copy module implements the copy of its common configuration files, such as VIMRC, screen, TMUX,BASHRC and so on.
Finally, copy my private key to the new machine's home directory, using the above VARs set the variable user.
After the completion of each time a new machine for you to maintain, only need to add the machine to the hosts inside, and then run to change playbook can, save time and effort.
Welcome to Add.
This article is from "Tianya Horizon" blog, please be sure to keep this source http://shanker.blog.51cto.com/1189689/1783379
Ansible Bulk Rapid initialization of new machine operations environment