Essay -7 Ansible-

Extended Ansible plug-in system.

Sometimes, if Ansible built-in plug-ins can not meet the demand, we can write your own new plug-ins.

Consider the following cases can develop new plug-ins:

1, except Paramiko, native SSH, Local, Winrm other connections, desired communication mode based on the new Ansible interact with a remote host.

2, in addition to the built-in with_items, with_fileglob vitro cycle, desirable to have a new way to navigate.

3, in addition to the built-in way to call host_vars, group_vars variables, we want new variables defined way.

4, in addition to the built-in template rendering jinja2, to_yaml, to_json such as filters, hope to have a new filter.

5, define a new callback mechanism, in response to events after capturing new custom response form.

The result on stdout output processing;

Increase logging, such as inserting the mysql, redis, mongodb;

Increased incident response methods, such playbook return success, send mail to each department.

 

 

 

 

Plug-storage location:

 

 

 Downloaded from the plug-in template GitHub (download action plug-ins, callback plug, plug, etc. Connection) above to the corresponding directory, and

It can be modified accordingly.

 

Example: write filter plug deal_list_num.py

/usr/share/ansible/plugins/filter/deal_list_num.py

 

 

 

 

Follow-up needs to imitate this to write. Here the data is | in front of the symbol numbers.

num_list | positive

That is, as the data transmitted to the num_list positive function. If you need two positive argument, it should be written as positive (parameter 2). Parameter 1 is the default data, without having to transfer.

 

After the definition of a good plug-in, we have to prepare yml file, to use our own plug-ins.

 

 

 

Execution, look at the results:

 

 

 

Analysis: In yml, we use the "| positive", "| negative", "| no_less_than" and other means.

When ansible see | when you know that this is called filtering. So it go

 

Start looking. After seeing deal_list_num.py, it calls inside the class, and call filters methods of the class. And just filters method returns three other methods.

They are positive, negative, no_less_than. So we call | positive, it is just a method called positive eventually return the desired result.

 

If you want to return to the task of printing the results to the terminal. You can call debug. It had previously been the default.

 

filter and callback plug-in is the more important of two, often you need to write to master.

Other plug-ins are used less. You can not control temporarily.

 

The catalog is a custom plug-in base. They are written here.

 

================= password authentication

1, the use of password authentication

First, fill in the username and password in the hosts file.

 

 

Then execute the command:

 

 

This command is equivalent to:

ssh [email protected] "whoami"

Finally yangling need to enter the password.

 

High availability architecture

 

Guess you like

Origin www.cnblogs.com/t-road/p/11469049.html