yum install ansible
yum install epel-release yum install ansible
useradd ansible echo 'ansible:ansible' | chpasswd <- change password cp -pi /etc/sudoers{,.`date '+%Y%m%d'`} echo "ansible ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
useradd ansible echo 'ansible:ansible' | chpasswd <- change password
su - ansible ssh-keygen -t rsa ssh-copy-id x.x.x.x <- Copy Publick Key to Target Server
[ansible@centos7 ~]$ ansible all -i 192.168.0.37, -a "hostname" -k SSH password: 192.168.0.37 | SUCCESS | rc=0 >> centos7b
cd /home/ansible mkdir ansible1 <- ansible working directory cd ansible1 touch hosts vi hosts ----------------------- [test] 192.168.0.37 -----------------------
[ansible@centos7 ansible1]$ ansible test -i hosts -a "hostname" -k SSH password: 192.168.0.37 | SUCCESS | rc=0 >> centos7b [ansible@centos7 ansible1]$
[ansible@centos7 ansible1]$cat hosts ---------------------------- [all:vars] ansible_ssh_pass=ansible [test] 192.168.0.37 ---------------------------- [ansible@centos7 ansible1]$ ansible test -i hosts -a "hostname" 192.168.0.37 | SUCCESS | rc=0 >> centos7b [ansible@centos7 ansible1]$
[ansible@centos7 ansible1]$ cat hosts [test] 192.168.0.37 ansible_ssh_pass=ansible [ansible@centos7 ansible1]$ [ansible@centos7 ansible1]$ ansible test -i hosts -a "hostname" 192.168.0.37 | SUCCESS | rc=0 >> centos7b [ansible@centos7 ansible1]$
$ ansible testservers -a "/bin/date" $ ansible webservers -a "/sbin/reboot" -f 10 --sudo
$ ansible all -m ping $ ansible -i /tmp/hosts all -m ping
$ ansible group1 -i /tmp/hosts all -m command -a "touch /tmp/test1.txt"
$ ansible testserver -m shell -a 'echo $TERM'
$ ansible testservers -m copy -a "src=/etc/hosts dest=/tmp/hosts"
$ ansible testservers -m file -a "dest=/tmp/hosts mode=600 owner=root group=root" -s -K
$ ansible webservers -m yum -a "name=httpd state=installed"
$ man ansible NAME ansible - run a task on a target host(s) SYNOPSIS ansible <host-pattern> [-m module_name] [-a args] [options] ARGUMENTS host-pattern A name of a group in the inventory, a shell-like glob selecting hosts in inventory or any combination of the two separated by commas. OPTIONS -i PATH, --inventory=PATH The PATH to the inventory, which defaults to /etc/ansible/hosts. Alternatively you can use a comma separated list of hosts or single host with traling comma host,. -a 'ARGUMENTS', --args='ARGUMENTS' The ARGUMENTS to pass to the module. -m NAME, --module-name=NAME Execute the module called NAME. -s, --sudo Run the command as the user given by -u and sudo to root (deprecated, use become). K, --ask-become-pass Ask for privilege escalation password.