
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Overview on Ansible, a continuous deployment and configuration tool which provides large productivity gains to a wide variety of automation challenges.
Typology: Cheat Sheet
1 / 1
This page cannot be seen from the preview
Don't miss anything!
ungrouped.example.com #An ungrouped host [webservers] #A group called webservers beta.example.com ansible_host = 10.0.0.5 #ssh to 10.0.0. github.example.com ansible_ssh_user = abc #ssh as user abc [clouds] cloud.example.com fileuser = alice #fileuser is a host variable [moscow] beta.example.com #Host (DNS will resolve) telecom.example.com #Host(DNS will resolve) [dev1:children] #dev1 is a group containing webservers #All hosts in group webservers clouds #All hosts in group clouds
#Add Ansible repository $ sudo apt-add-repository ppa:ansible/ansible #Run the update command $ sudo apt-get update #Install Ansible package $ sudo apt-get install ansible #Check Ansible Version $ ansible – version
#Setting Up SSH Command $ sudo apt-get install openssh-server #Generating SSH Key $ ssh-keygen #Copy the SSH Key on the Hosts $ ssh-copy-id hostname #Check the SSH Connection $ ssh
#Set up hosts by editing the hosts' file in the Ansible directory $ sudo nano /etc/ansible/hosts #To check the connection to hosts #First change the directory to /etc/Ansible $ cd /etc/ansible #To check whether Ansible is connecting to hosts, use ping command $ ansible – m ping
#To set up SSH agent $ ssh-agent bash $ ssh-add ~/.ssh/id_rsa #To use SSH with a password instead of keys, you can use --ask-pass (-K) $ ansible europe - a "/sbin/reboot" - f 20 #To run /usr/bin/ansible from a user account, not the root $ ansible europe - a "/usr/bin/foo" - u username #To run commands through privilege escalation and not through user account $ ansible europe - a "/usr/bin/foo" - u username --become [--ask-become-pass] #If you are using password less method then use --ask-become-pass (-K) to interactively get the password to be use #You can become a user, other than root by using --become-user $ ansible europe - a "/usr/bin/foo" - u username --become --become-user otheruser [--ask-become-pass]
#Transfer a file directly to many servers $ ansible europe - m copy - a "src=/etc/hosts dest=/tmp/hosts" #To change the ownership and permissions on files $ ansible webservers - m file - a "dest=/srv/foo/a.txt mode=600" $ ansible webservers - m file - a "dest=/srv/foo/b.txt mode=600 owner=example group=example" #To create directories $ ansible webservers - m file - a "dest=/path/to/c mode=755 owner=example group=example state=directory“ #To delete directories (recursively) and delete files $ ansible webservers - m file - a "dest=/path/to/c state=absent
#To ensure that a package is installed, but doesn’t get updated $ ansible webservers - m apt - a "name=acme state=present" #To ensure that a package is installed to a specific version $ ansible webservers - m apt - a "name=acme-1.5 state=present" #To ensure that a package at the latest version $ ansible webservers - m apt - a "name=acme state=latest" #To ensure that a package is not installed $ ansible webservers - m apt - a "name=acme state=absent
#To ensure a service is started on all web servers $ ansible webservers - m service - a "name=httpd state=started" #To restart a service on all web servers $ ansible webservers - m service - a "name=httpd state=restarted" #To ensure a service is stopped $ ansible webservers - m service - a "name=httpd state=stopped
#Generate the SSH Key and connect hosts to control machine before writing and running playbooks. #Create a Playbook $ vi
#GitRep:https://foo.example.org/repo.git #Destination:/src/myapp $ ansible webservers - m git - a "repo=https://foo.example.org/repo.git dest=/src/myapp version=HEAD"
all All hosts in inventory