Ansible learning-ansible

Source: Internet
Author: User

Ansible learning-ansible

Ansible technologies (Automated O & M tools) are developed based on python.

Installation methods include yum, apt, pip, etc.

For example, pip: pip install ansible

The only requirement of ansible for the client is to have SSH and Python (if the python version is too low, install python-simplejson module)

The simplest ansible command:

Ansible-I/etc/ansible/hosts all-m command-a 'date'-u prod

Parameters:

-I specifies the location of the hosts file. hosts is a yaml file, and all indicates all groups in the hosts file.

-M specifies the ansible module. The command here indicates the ansible command module. There are many other modules, such as shell.

-A: Specify the args parameter.

-U indicates the user (because it is based on SSH authentication)

Common ansible commands:

Ansible # execute simple temporary commands (ad-hoc commands)

Ansible-playbook # execute playbook, playbook is a yaml file (as the main function of the Configuration Management Tool)

Ansible-doc # query ansible module documentation

Example:

---
-Hosts: cmdb
User: prod
Sudo: True
Tasks:
-Name: show the date
Shell: date
Y: show1
Handlers:
-Name: show1
Shell: ls

Run ansible-playbook user. yml

User. yml File

Hosts: Specifies the device group.

User: Specifies the ssh user

Sudo: whether to use the sudo permission

Tasks: keyword indicates the execution action

Name: name an action.

Yum: ansible specified Module

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.