Thursday, March 24, 2016

[Ansible] My first step to use Ansible

Before get started to use Ansible, you need to add public ssh key to your remote Server first. If you want to setup SSH keys to allow logging in without a password, you can do so with a single command.
The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys:

ssh-keygen -t rsa
Then use this command to push the key to the remote server, modifying it to match your server name.
cat ~/.ssh/ | ssh user@hostname 'cat >> .ssh/authorized_keys'

So, from now on you are able to try Ansible to control your remote server.

# sudo pip install ansible
# sudo mkdir /etc/ansible
# cd /etc/ansible/
# vim hosts
  ==> [my_vm]

# ansible my_vm --private-key=/home/liudanny/.ssh/id_rsa --user=ubuntu -m ping
# ansible my_vm -m ping --user ubuntu | success >> {
    "changed": false,
    "ping": "pong"
ansible my_vm --user=ubuntu -a "/bin/echo hello" | success | rc=0 >>

If the above steps work fine, we can follow this document to create an instance and check services on OpenStack. Here you go:

OpenStack-Ansible Installation Guide

No comments: