Professional Documents
Culture Documents
co
File Transfer
#Transfer a file directly to many servers
SSH Key Generation & Install Ansible $ ansible europe -m copy -a "src=/etc/hosts dest=/tmp/hosts"
#To change the ownership and permissions on files
SSH Key Generation $ ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600" $ ansible webservers -m file -a "dest=/srv/foo/b.txt
Ansible uses SSH to communicate between the nodes. mode=600 owner=example group=example"
#To create directories
#Setting Up SSH Command $ ansible webservers -m file -a "dest=/path/to/c mode=755 owner=example group=example state=directory“
$ sudo apt-get install openssh-server #To delete directories (recursively) and delete files
#Generating SSH Key $ ansible webservers -m file -a "dest=/path/to/c state=absent
$ ssh-keygen
#Copy the SSH Key on the Hosts Manage Packages Manage Services
$ ssh-copy-id hostname
#Check the SSH Connection #To ensure a service is started on all web servers
#To ensure that a package is installed, but doesn’t get updated
$ ssh <nodeName> $ ansible webservers -m service -a "name=httpd
$ ansible webservers -m apt -a "name=acme state=present"
state=started"
#To ensure that a package is installed to a specific version
Install Ansible $ ansible webservers -m apt -a "name=acme-1.5 state=present"
#To restart a service on all web servers
$ ansible webservers -m service -a "name=httpd
To install Ansible in Debian Linux, follow the following steps: #To ensure that a package at the latest version
state=restarted"
$ ansible webservers -m apt -a "name=acme state=latest"
#Add Ansible repository #To ensure a service is stopped
#To ensure that a package is not installed
$ sudo apt-add-repository ppa:ansible/ansible $ ansible webservers -m service -a "name=httpd
$ ansible webservers -m apt -a "name=acme state=absent
#Run the update command state=stopped
$ sudo apt-get update
#Install Ansible package Deploying From Source Control
$ sudo apt-get install ansible
#Check Ansible Version #GitRep:https://foo.example.org/repo.git #Destination:/src/myapp
$ ansible –version $ ansible webservers -m git -a "repo=https://foo.example.org/repo.git dest=/src/myapp version=HEAD"