Ansible Maintenance Automation Tools

Source: Internet
Author: User

Ansible Maintenance Automation Tools

software Package Installation RPM-IVH Http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpmyum Install Ansible-y
Configure the Keyless key on the master server to generate Ssh-key and distribute to all clients ssh-keygen-t RSA "All-in-a-  return" ssh-copy-id-i ~/.ssh/id_rsa.pub "Client IP Address"

after the configuration installation is complete, configure the configuration item ——. ansible.cfg first. When Ansible executes, it looks for configuration items in the following order:

* ANSIBLE_CONFIG (environment variable)

* ANSIBLE.CFG (under current directory)

*. ansible.cfg (under User's home directory)

*/etc/ansible/ansible.cfg

The hosts configuration is loaded from this configuration by default ansible, so you can specify the default Hosts file address by modifying the. Ansible.cfg:

[Defaults]hostfile=/users/the5fire/hosts


There are several parameters that need to be recorded:
-u username # specify ssh

--sudo [-K] # If root permission is required, the-K parameter is used to enter the root password

Define the Hosts file:

The ansible hosts default in the/etc/ansible/directory, which prompts ansible to support the domain name and IP two client naming formats, where a "slave" group is defined vim/etc/ansbile/hosts [slave]

192.168.17.18
192.168.17.19
vim/etc/ansible/hosts  [webhosts]  172.16.  10.22 ansible_ssh_user=root ansible_ssh_pass=172.16. 10.33 ansible_ssh_user=root ansible_ssh_pass=guoting explanation  Ansible_ssh_user=root is SSH login user  ansible_ssh_pass=guoting is SSH login password 3, test each module  
Note the usage of each module can be used ansible-doc MOD to see the most common uses for example ansible-doc copy ansible commands ' Mod_arv' supported modules can be viewed using ansible-doc-l

The above ad hoc refers to the execution of a temporary not need to save the command, then how to execute the complex command? So there is the Playbook command: ansible-playbook .

Playbook (script) is the need to define a script or a configuration file and then define what to do.

Example: Output the current user name to the Whoami.rst file:

Cat/etc/ansible/playbook.yml
----Hosts:slave # The group defined in the Hosts file Remote_user:root # If you are the same as the current user, you do not need to specify tasks: # Tasks are keywords that indicate which tasks to perform-Name:whoami # Name is the name of the task shell:'whoami > Whoami.rst'# The Shell is the module that is specified for use, and the single quotation mark is the command. -hosts:slave remote_user:root tasks:-Name:whoami copy:src=~/hosts dest=~/hosts.dest # Local copy to remote notify: # If the ~/hosts.dest file sends a change after copy is executed, execute - Clear Copy handlers:-Name: clear Copy # calls the handler shell:'MV ~/hosts.dest Hosts.del'# rename

Or

Cat Playbook.yml

- hosts:slave  remote_user:root  tasks:      - name:whoami        copy:src=~/hosts dest=~/ hosts.dest       - name:clear copy        'mv ~/hosts.dest hosts.del'

Ansible Maintenance Automation Tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.