ansible -k all -m ping
ansible -k all -m command -a "ping -c 2 www.baidu.com"
ansible -k -i /etc/ansible/hosts all -m command -a "date"
ansible -k 172.24.77.242 -m command -a "df -h"
ansible -k all -m copy -a 'src=/etc/passwd dest=/tmp/ mode=755 owner=root'
ansible srv -m fetch -a ‘src=/root/a.sh dest=/data/scripts’
1、将ansible主机上的压缩包在本地解压缩后传到远程主机上, 设置copy=yes.
2、将远程主机上的某个压缩包解压缩到指定路径下,设置copy=no
ansible srv -m unarchive -a 'src=foo.tgz dest=/var/lib/foo'
ansible srv -m unarchive -a 'src=/tmp/foo.zip dest=/data copy=no mode=0777'
ansible srv -m unarchive -a 'src=https://example.com/example.zip dest=/data copy=no'
ansible all -m archive -a 'path=/etc/sysconfig dest=/data/sysconfig.tar.bz2 format=bz2 owner=wang mode=0777'
ansible node1 -m hostname -a “name=websrv”
ansible -k all -m copy -a 'content="hello world" dest=/tmp/jay.txt mode=755 owner=root'
ansible -k all -m copy -a 'content="hellow world" dest=/tmp/jay.txt backup=yes mode=755 owner=root'
ansible web -k -m yum -a "name=tree state=installed"
ansible all -k -m yum -a "name=tree state=absent"
ansible all -k -m yum -a "name=tree state=installed disable_gpg_check=no"
ansible -k 172.24.77.* -m file -a "path=/tmp/`date +%F` state=directory mode=755"
ansible -k 172.24.77.* -m file -a "path=/tmp/jay.txt state=touch mode=755"
ansible -k 172.24.77.* -m user -a "name=jay home=/tmp/"
ansible -k 172.24.77.* -m user -a "name=jay home=/tmp/ shell=/sbin/nologin"
ansible -k 172.24.77.* -m user -a "name=jay state=absent force=yes"
ansible web -k -m yum -a "name=ntpdate state=installed"
ansible -k web -m cron -a "minute=1 hour=0 day=* month=* weekday=* name='Ntpdate server for sync time' job='/usr/sbin/ntpdate 139.224.227.121'"
ansible -k web -m cron -a "name='Ntpdate server for sync time' state=absent "
ansible -k web -m cron -a "minute=1 hour=0 day=* month=* weekday=* name='Ntpdate server for sync time' backup=yes job='/usr/sbin/ntpdate pool.ntp.org'"
ansible web -k -m yum -a "name=rsync state=installed"
ansible -k web -m synchronize -a 'src=/tmp/ dest=/tmp/'
ansible -k all -m synchronize -a 'src=/tmp/ dest=/tmp/' compress=yes delete=yes rsync_opts=--no-motd,--exclude=.txt'
ansible -k all -m shell -a "/bin/sh /tmp/test.sh>>/tmp/var.log"
ansible -k all -m shell -a "mkdir -p 'date + %F' chdir=/tmp/ state=directory warn=no"
ansible -k all -m shell -a "ps -ef|grep httpd"
ansible -k all -m shell -a "crontab -l"
ansible -k all -m service -a "name=httpd state=restarted"
ansible -k all -m service -a "name=network args=eth0 state=restarted"
ansible -k all -m service -a "name=nfs enabled=yes runlevel=3,5"
cd /etc/ansible/
vim install-nginx.yml
-hosts:all
remote_user:root
tasks:
-name:install-nginx-devel
yum:name=pcre-devel,pcre,zlib-devel state=installed
-name:install-nginx-process
shell:cd /usr/local/src;wget http://nginx.org/download/nginx-1.16.1.tar.gz;tar -xzf nginx-1.16.1.tar.gz;cd nginx-1.16.1;./configure --prefix=/usr/local/nginx
;make;make install
chmod +x install-nginx.yml
./install-nginx.yml
Dictionary:字典,通常由多个key与value构成
name: Example Developer
job: Developer
skill: Elite
{name: Example Developer, job: Developer, skill: Elite}
name: John Smith标签:tmp,name,示例,dest,ansible,state,Ansible From: https://blog.51cto.com/u_13688209/6081016
age: 41
gender: Male
spouse:
name: Jane Smith
age: 37
gender: Female
children:
- name: Jimmy Smith
age: 17
gender: Male
- name: Jenny Smith
age 13
gender: Female