Ansibleインストール構成(linuxクライアント)

5300 ワード

yumインストール
yum install epel-release -yyum install ansible –y
ansibleプロファイル
inventory = /etc/ansible/hosts1              inventory     ,        ansible            。           :
library = /usr/share/ansible1            ansible     ,        ,           ,         ,  library        ansible     。      :
ansible        ,     “ : ”     ,          playbook    ./library  。
forks = 51                                               ansible             ,  ansible 1.3  ,fork                      ,      5       。         ,                      ,    50 100。   5       。
sudo_user = root1                                          ,    playbook         。      :
remote_port = 221                                         ,   22。        SSH  ,               。 
host_key_checking = False1              SSH     。     True False,                
timeout = 601                                        SSH       ,    。      :
log_path = /var/log/ansible.log1            ,    ansible             ,    log_path       ansible     。      :

ansible公開秘密鍵の構成
1、まず鍵を生成する##次の命令を実行してから、車に戻ればいい![root@CentOS7-master ~]# sudo ssh-keygen -t rsa12
2、その後、ホストに鍵を配布する:##ホストリストに追加されたすべてのIPアドレスまたはホスト名は、すべて次の命令で実行しなければならない.[root@CentOS7-master~]#sudo ssh-copy-id root@ホスト名またはIPアドレス12
3、ssh-copy-id-i~/.ssh/id_rsa.pub [email protected]: ssh-copy-id: command not found
#   :
yum -y install openssh-clientsansible

ansibleホストリスト設定、編集/etc/ansible/hosts、ansibleホストに他のすべてのホストのhostnameを追加
vim/etc/hosts 192.168.123.45 server-1192.168.123.46 server-2192.168.123.47 server-3192.168.123.48 server-4192.168.123.49 server-5 192.168.123.50 server-6
制御側がpemファイルである場合、pemファイルをansible-server側指定パスに転送します.
vim /etc/ansible/hosts  
[zhandian1]
server-1    ansible_ssh_user=centos ansible_ssh_private_key_file=/home/centos/aws_secret/nginx.pem
server-2    ansible_ssh_user=centos ansible_ssh_private_key_file=/home/centos/aws_secret/nginx.pem
server-4    ansible_ssh_user=centos ansible_ssh_private_key_file=/home/centos/aws_secret/nginx.pem
server-5    ansible_ssh_user=centos ansible_ssh_private_key_file=/home/centos/aws_secret/nginx.pem
server-6    ansible_ssh_user=centos ansible_ssh_private_key_file=/home/centos/aws_secret/nginx.pem

sshポートが変更された場合はansibleを追加する必要があります.ssh_port=3333
オープン・セキュリティ・グループ、22ポート
ansible   
/usr/bin/ansible                    # Ansibe AD-Hoc         ,          
/usr/bin/ansible-doc            # ansible         
/usr/bin/ansible-galaxy         #   /       Roles        ,     
/usr/bin/ansible-playbook   # ansible              
/usr/bin/ansible-pull               # ansible         ,          (    ,       ,            )
/usr/bin/ansible-vault          # ansible       
/usr/bin/ansible-console        # ansible  Linux Consoble               

ansible常用コマンド
                                                ansible all -m shell -a 'sudo sh aaa.sh '
        ,      root                         ansible '*' -m file -a "dest=/tmp/t.sh mode=755 owner=root group=root"
             ,  3               ansible '*' -m cron -a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.254.139"'
            aaa,gid 2017                ansible all -m group -a 'gid=2017 name=a'
          aaa,  aaa                         ansible all -m user -a 'name=aaa groups=aaa state=present'
                                                    ansible all -m user -a 'name=aaa groups=aaa remove=yes'
      httpd                                         ansible all -m yum -a "state=present name=httpd"
        ,                                   ansible all -m service -a 'name=httpd state=started enabled=yes'
                                                    ansible '*' -m ping
                                                    ansible '*' -m command -a 'uptime'
                                                ansible '*' -m script -a '/root/test.sh'
    zabbix                                          ansible '*' -m shell -a 'ps aux|grep zabbix'
  shell                                                 ansible '*' -m raw -a "ps aux|grep zabbix|awk '{print \$2}'"
                                                    ansible '*' -m file -a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link"
                                                    ansible '*' -m file -a "path=/tmp/resolv.conf state=absent"
                                                ansible '*' -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"
     hostname                                       ansible all -m raw -a 'hostname|tee'
   url       /tmp                               ansible all -m get_url -a 'url=http://10.1.1.116/favicon.ico dest=/tmp'
![](https://s1.51cto.com/images/blog/202001/11/e984a040a871de7ff58f52935e4bcf8f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)