Ansible is a great tool for config management on a set of remote machines. However, Ansible can be used to execute commands locally too. My uses for Ansible include writing a"playbook" (i.e. an Ansible script) to install software locally if I get a new laptop and provisioning virtual machines in amazon's EC2.
In the this post you will see how to execute a one liner on set of hosts. More fun stuff will be in later posts. :-)
1. Firstly, install Ansible. Assuming you use homebrew (and if you are on a mac you really should be!) execute the following:
brew update
brew install ansible
2. Create a working directory.
mkdir ansible_wd
cd ansible_wd
3. Within your current directory create a file called hosts and open it with your favourite editor. This hosts file will contain a list of machine names/ip addresses etc.
vim hosts
4. In hosts paste the following:
[group_name]
localhost
This means you have a group called [group_name] (change this to something sensible!) with one host in the group - localhost.
5. Assuming you have an RSA key set up , you need to paste your public key in ~/.ssh/authorized keys.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
6. Now you are ready to run your first Ansible command:
Make sure you have your sound on and execute the following:
ansible all -i hosts -a "say hello ansible"
What does this do?
Another example to install htop locally using homebrew:
ansible group_name -i hosts -a "brew install htop"
So you might be wondering what is the point? Why would I bother setting up Ansible to execute local commands like "brew install htop" in a more roundabout way than simply typing the command? As mentioned at the start of the post, one useful thing you can do is add commands to an Ansible script which you can execute on any machine to install software. This will save massive amounts of time when you get your new dev machine and you can magically install everything by running one script. For me, it's open-jdk, htop, wget among other things.
You might wonder why can't you simply write a shell script to execute a series of steps? Well you could, but Ansible is a bit cleverer than that - it can manage state and do all sorts of crazy stuff which we will see in coming posts.
In the next post we will learn how create an Ansible playbook to execute statements on remote or local machines.
In the this post you will see how to execute a one liner on set of hosts. More fun stuff will be in later posts. :-)
1. Firstly, install Ansible. Assuming you use homebrew (and if you are on a mac you really should be!) execute the following:
brew update
brew install ansible
2. Create a working directory.
mkdir ansible_wd
cd ansible_wd
3. Within your current directory create a file called hosts and open it with your favourite editor. This hosts file will contain a list of machine names/ip addresses etc.
vim hosts
4. In hosts paste the following:
[group_name]
localhost
This means you have a group called [group_name] (change this to something sensible!) with one host in the group - localhost.
5. Assuming you have an RSA key set up , you need to paste your public key in ~/.ssh/authorized keys.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
6. Now you are ready to run your first Ansible command:
Make sure you have your sound on and execute the following:
ansible all -i hosts -a "say hello ansible"
What does this do?
- 'all' means execute on all hosts
- '- i' option means inventory which is your hosts file
- '-a' means you are executing an ad-hoc command on the relevant hosts.
- "say hello ansible" is the command to be executed on every hosts. Note that on Mac OS X, say should be installed by default.
Another example to install htop locally using homebrew:
ansible group_name -i hosts -a "brew install htop"
So you might be wondering what is the point? Why would I bother setting up Ansible to execute local commands like "brew install htop" in a more roundabout way than simply typing the command? As mentioned at the start of the post, one useful thing you can do is add commands to an Ansible script which you can execute on any machine to install software. This will save massive amounts of time when you get your new dev machine and you can magically install everything by running one script. For me, it's open-jdk, htop, wget among other things.
You might wonder why can't you simply write a shell script to execute a series of steps? Well you could, but Ansible is a bit cleverer than that - it can manage state and do all sorts of crazy stuff which we will see in coming posts.
In the next post we will learn how create an Ansible playbook to execute statements on remote or local machines.
Thanks for sharing wonderful information with us, It's really useful for learners keep share content on Devops Online Training
ReplyDeletemmorpg oyunlar
ReplyDeleteİNSTAGRAM TAKİPCİ SATİN AL
tiktok jeton hilesi
tiktok jeton hilesi
Saç ekimi antalya
instagram takipçi satın al
Instagram takipçi satin al
Mt2 pvp serverler
instagram takipçi satın al
SMM PANEL
ReplyDeleteSmm panel
iş ilanları
instagram takipçi satın al
hırdavat
beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi