Ansible management command

Ansible management command

(1)ansible

This command is one of the commands with high usage rate in daily work, mainly used for temporary one-time operation;

(2)ansible-doc

Ansible module documentation, for each module, there are detailed instructions and application cases;

(3)ansible-galaxy

It can be simply understood as the function of Github or PIP. It is an official role sharing function platform of Ansible. You can simply share and install the role through the Ansible Galaxy command;

(4)ansible-playbook

It is the most frequently used command in daily application. Its working mechanism is to achieve batch management by reading the pre written playbook file;

(5)ansible-pull

Another working mode of ansible is pull mode. Ansible uses push mode by default;

(6)ansible-vault

Mainly used for configuration file encryption;

(7)ansible-console

It allows users to use Ansible's built-in commands like a Shell on Ansible console virtual terminals.

Detailed command

ansible command

Command format

ansible <host-pattern> [options]

--version Display version
-a Module parameters (if any)
-m module Specify module, default is command
-v Detailed process –vv -vvv More detailed
--list-hosts Display the list of hosts, which can be abbreviated--list
-k, --ask-pass Prompt connection password, default Key Verification
-K,--ask-become-pass Prompt use sudo Password
-C, --check Inspection, not carried out
-T, --timeout=TIMEOUT Timeout for command execution, default 10 s
-u, --user=REMOTE_USER User executing remote execution
-U, SUDO_USER, --sudo-user Appoint sudu user
-b, --become Replace the old version sudo switch

View version number

# ansible --version
ansible 2.6.7

View client status

# ansible server1 -m ping
192.168.61.130 | SUCCESS => {
"changed": false, 
"ping": "pong"
}

View host list

# ansible server1 --list
hosts (1):
192.168.61.130

Copy files to client

# ansible server1 -m copy -a 'src=/wh_k/test1.txt dest=/wh_k backup=yes'
192.168.61.130 | SUCCESS => {
"changed": true, 
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
"dest": "/wh_k/test1.txt", 
"gid": 0, 
"group": "root", 
"md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
"mode": "0644", 
"owner": "root", 
"size": 0, 
"src": "/root/.ansible/tmp/ansible-tmp-1544361826.12-278173604489771/source", 
"state": "file", 
"uid": 0

Ansible doc command

Command format

ansible-doc [options] [module...]

ansible-doc Command heel[options]Parameter or[Module name],Display module instructions

List modules

# ansible-doc -l
a10_server                                           Manage A10 Networks AX/SoftAX/Thunder/vThunder devices' server object.       
a10_server_axapi3                                    Manage A10 Networks AX/SoftAX/Thunder/vThunder devices 
....
....

Module description

# ansible-doc ping
> PING    (/usr/lib/python2.6/site-packages/ansible/modules/system/ping.py)

A trivial test module, this module always returns `pong' on successful contact. It does not make
...

Ansible playbook command

Command format

ansible-playbook playbook.yml

ansible-playbook Command heel YML Formatted playbook Documents, performing pre arranged task sets

Command example

# ansible-playbook nginx.yml

Tags: Linux ansible sudo github pip

Posted on Sun, 01 Dec 2019 23:38:10 -0500 by hellonoko