Introduction of ansible configuration file and command introduction

Source: Internet
Author: User
Tags vars ssh port

1. ansible configuration file

[Email protected] ansible]# rpm-ql ansible |grep etc/etc/ansible/etc/ansible/ansible.cfg/etc/ansible/hosts/etc/ Ansible/roles

The Ansible.cfg file can set some default values so that we do not need to enter the same content many times.

Where should I put the ansible.cfg file?

Ansible find the Ansible.cfg file in the following location and order:

1. Ansible_config the file specified by the environment variable.

2../ansible.cfg (ansible.cfg in the current directory).

3. ~/.ansible.cfg (. Ansible.cfg in the home directory).

4. /etc/ansible/ansible.cfg.

Configuration file ansible.cfg Common configuration items:

[defaults]# some basic default values...inventory =/etc/ansible/hosts#library =/usr/share/my_modules/remote_ TMP = $HOME/.ansible/tmppattern = *forks = 5poll_interval = 15sudo_user = Root#ask_sudo_pass = T Rue#ask_pass = Truetransport = Smart#remote_port = 22

Also easier to understand is that we need to operate the host list, the default SSH port, the number of ansible processes, sudo users and so on

2. List of host lists:

Host list manifest Hosts file: (all managed hosts must be placed in the hosts, not necessarily this hosts, can be specified using the-i parameter of the ansible)

[testhost]172.16.162.130

This is also a common format, Testhost represents a group, 172.16.162.130 represents a member, and can have multiple members, such as

[testhost]172.16.162.130172.16.162.131

If the host has a similar naming of the rules, you can use the list form:

[testwebservers]web[01:10].lansgg.com

Represents web01.lansgg.com web02.lansgg.com-------web10.lansgg.com


Host variables:

Add a variable to the hosts definition host, which can be referenced in playbook

[testdbservers]db1.lansgg.com db_port=3306 server-id=1db2.lansgg.com db_port=3305 server-id=2

Group variables:

Refers to all hosts within a group assigned the same variable, which can be referenced in playbook

[webserver]web01.lansgg.comweb02.lansgg.com[webserver:vars]http_port=8080

Group nesting:

A group can contain other groups, or you can assign variables to hosts in a group, which can be used in Ansible-playbook, and ansible can not

[Web]web01.lansgg.comweb02.lansgg.com[db]db01.lansgg.comdb02.lansgg.com[all:children]webdb[all:vars]ntp_server =172.16.100.100

You can also specify all


3. Ansible command format

Synopsis Ansible 

command example:

[Email protected] ansible]# ansible testhost-m command-a ' Date ' 172.16.162.130 | Success | Rc=0 >>tue Feb 17:22:30 CST 2016

---host-pattern specifies which hosts to operate on, that is, the Testhost host group in the example

The number of concurrent threads---forks started

---module_name command in the module example to be used

---the date in the parameters example of the args module


This article is from the "Big Wind" blog, please be sure to keep this source http://lansgg.blog.51cto.com/5675165/1744699

Introduction of ansible configuration file and command introduction

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.