The ansibles hoc command line

 

ansible

Ansible: Ansible core program
Python
Paramiko
Jiaja2
Yam1

Host Lnventory: record every information managed by the host Ansible, information including ssh port, root account password, ip addresses, and so on. Can be loaded via file, can be loaded by CMDB
playbooks: YAML format file, multiple tasks defined in a file, you can use a unified call "play" is used to define those who need to call the host module to complete the function.
Core Modules : Ansible perform any administrative tasks are not completed by the Ansible themselves, but to complete the core modules; before Ansible management server, the first call core modules in the module, and then specify the management host host Lnventory in, you can complete a management host.
Custom Modules: custom modules, complete Ansible core module function can not be completed, this module supports any language.
Connection Plugins: connection plug, Ansible and Host communication using 1.Ansible advantages: • Stupied the Simple, easy to get started, the learning curve smoothing • SSH by default, safe, no need to install client • configuration is simple, powerful, and strong expansion • Support API and custom modules can be easily extended by Python customized • by Playbooks powerful configuration, status management • provides a powerful, strong operational management Web interface and REST API interfaces --AWX platform • idempotency: operating a repeated several times the same result
 








2.ansible installation
1. Release-yum the install EPEL
2. yum the install ansible -Y
3.ansible client configuration (no password required)
The first method:
1. Server: SSH-keygen
2. SCP id_rsa.pub [email protected] .254.25: /root/.ssh/authorized_keys
second method:
1.vim / etc / ansible / the hosts
[ZXW]
192.168.126.7 ansible_ssh_user = 22 is the root ansible_ssh_port ansible_ssh_pass = 123 =
192.168.126.6 ansible_ssh_user the root ansible_ssh_port = = = 22 is ansible_ssh_pass 123
-
 3. the three modes
hoc: command
palybooks: script: script
roles: roles
4.ansible commonly used commands
• ansible-doc -l # View supported modules
• ansible-doc -s MODEL_NAME # View module usage
• ansible application of basic commands
ansible 1. <Host-pattern> [Options]
-f Forks: start concurrent default number of concurrent threads: 5
-m model_name: module to be used
-a args: unique parameter
whether • ansible zxw -m ping # view the client end of normal ping the client the p-
! 192.168.126.7 | FAILED => {
"msg": "A the Using SSH password INSTEAD of a Key iS Not possible because the Host Key Checking iS Enabled and sshpass does Not Support the this. Please the Add the this Host apos Fingerprint to your the known_hosts File to Manage the this Host. "
}
from the system outputs can be basically understood since the machine - Fingerprint /.ssh/known_hosts file key string and have, when the first connection ssh generally will be prompted for confirmation to the yes key string is added to ~ / .ssh / known_hosts file

For this reason, you can modify the configuration file /etc/ansible/ansible.cfg

[root@zxw8 ~]# vim /etc/ansible/ansible.cfg

# uncomment this to disable SSH key host checking
host_key_checking = False
• ansible webserver -m setup #查看客户端信息
• ansible webserver -m copy -a 'src=/root/git_test/code.txt dest=/root/test' #copy文件到cient端
[root@zxw8 ~]# ansible zxw -m copy -a 'src=/root/zxw dest=/root/'
组名 -m'模块 -a 参数 (原文件 ,目标文件)
• ansible webserver -m user -a "name=test state=present" #创建test用户


• ansible webserver -m user -a "name=test state=absent" #删除test用户
• ansible webserver -m yum -a ‘name=epel-relese state=latest‘ #yum安装
[root@zxw8 ~]# ansible zxw -m service -a 'name=network state=started'

启动
[root@zxw8 ~]# ansible zxw -m service -a 'name=network state=stoped'
关闭
[root@zxw8 ~]# ansible zxw -m service -a 'name=network state=retarted'
重启
• ansible webserver -m script -a ‘/tmp/test.sh‘ #运行脚本
• ansible webserver -m command 'date' #查看时间
[root@zxw8 ~]# ansible zxw -m command -a 'date "+%F %T"'
组名 -m 模块 -a ‘命令’
命令警告
[root@zxw8 ~]# vim /etc/ansible/ansible.cfg
# instead of shelling out to the git command.
command_warnings = False
打开注释

 

Guess you like

Origin www.cnblogs.com/itzhao/p/11262003.html