2012-05-13 17:00:02 +02:00
Getting Started
===============
2012-03-07 17:35:18 +01:00
2012-08-28 21:41:10 +02:00
.. contents ::
:depth: 2
2013-10-05 00:14:54 +02:00
.. _gs_about:
2013-09-29 19:29:11 +02:00
About
`` ` ``
2012-03-08 19:36:47 +01:00
2013-10-03 03:51:21 +02:00
Now that you've read :doc: `intro_installation` and installed Ansible, it's time to dig in and get
2013-09-29 19:29:11 +02:00
started with some commands.
2012-03-08 19:36:47 +01:00
2013-10-03 03:45:57 +02:00
What we are showing first are not the powerful configuration/deployment/orchestration of Ansible, called playbooks.
Playbooks are covered in a seperate section.
2013-10-03 03:51:21 +02:00
This is basically about how to get going initially. Once you have this down, read :doc: `intro_adhoc` for some more
2013-10-03 03:45:57 +02:00
detail, and then you'll be ready to dive into playbooks.
2013-10-05 00:14:54 +02:00
.. _remote_connection_information:
2013-09-29 19:29:11 +02:00
Remote Connection Information
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2012-04-26 04:25:13 +02:00
2013-09-29 19:29:11 +02:00
Before we get started, it's important to understand how Ansible is communicating with remote
machines over SSH.
2012-03-08 19:36:47 +01:00
2013-09-29 19:29:11 +02:00
By default, ansible 1.3 and later will try to use native
OpenSSH for remote communication when possible. This enables both ControlPersist (a performance feature), Kerbos, and options in ~/.ssh/config such as Jump Host setup. When using Enterprise Linux 6 operating systems as the control machine (Red Hat Enterprise Linux and derivatives such as CentOS), however, the version of OpenSSH may be too old to support Control Persist. On these operating systems, Ansible will fallback into using a high-quality python implementation of
OpenSSH called 'paramiko'. If you wish to use features like Kerberized SSH and more, consider using Fedora, OS X, or Ubuntu as your control machine until a newer version of OpenSSH is available for your platform.
2012-03-08 19:36:47 +01:00
2013-09-29 19:29:11 +02:00
In Ansible 1.2 and before, the default was strictly paramiko and native SSH had to be explicitly selected with -c ssh or set in the configuration file.
2013-02-16 22:06:30 +01:00
2013-10-03 04:09:02 +02:00
If talking with some remote devices that don't support SFTP, you can switch to SCP mode in :doc: `intro_configuration` .
2012-03-08 19:36:47 +01:00
2013-09-29 19:29:11 +02:00
When speaking with remote machines, Ansible will by default assume you are using SSH keys. To enable password auth, supply the option --ask-pass where needed. If using sudo features and when sudo requires a password, also supply --ask-sudo-pass as appropriate.
2013-02-16 22:06:30 +01:00
2013-10-03 04:09:02 +02:00
Ansible also contains a feature called :doc: `playbooks_acceleration` which uses SSH for initial key exchange
2013-09-29 19:29:11 +02:00
and then communicates over a high speed encrypted connection.
2013-02-16 22:06:30 +01:00
2013-09-29 19:29:11 +02:00
While it may be common sense, it is worth sharing: Any management system benefits from being run near your machines you are being managed. If running in a cloud, onsider running Ansible from a machine inside that cloud.
2012-03-08 19:36:47 +01:00
2013-09-29 19:29:11 +02:00
As an advanced topic, ansible doesn't just have to connect remotely over SSH. The transports are pluggable, and there are options for managing things locally, as well as managing chroot, lxc, and jail containers. A mode called 'ansible-pull' can also invert the system and have systems 'phone home' via scheduled git checkouts to pull configuration directives from a central repository.
2013-02-16 22:06:30 +01:00
2013-10-05 00:14:54 +02:00
.. _your_first_commands:
2012-03-08 19:36:47 +01:00
Your first commands
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2013-09-29 19:29:11 +02:00
Now that you've installed Ansible, it's time to get started with some basic tests.
2012-03-18 17:55:18 +01:00
2012-03-17 22:00:41 +01:00
Edit (or create) /etc/ansible/hosts and put one or more remote systems in it, for
2012-03-09 20:39:29 +01:00
which you have your SSH key in `` authorized_keys `` ::
2012-03-08 19:36:47 +01:00
192.168.1.50
aserver.example.org
bserver.example.org
2013-10-03 03:51:21 +02:00
This is an inventory file, which is also explained in greater depth here: :doc: `intro_inventory` .
2013-10-03 03:45:57 +02:00
2013-09-29 19:29:11 +02:00
We'll assume you are using SSH keys for authentication. Set up SSH agent to avoid retyping passwords:
2012-03-08 19:36:47 +01:00
2012-08-13 20:51:36 +02:00
.. code-block :: bash
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa
2012-03-09 05:05:52 +01:00
2013-01-20 22:24:03 +01:00
(Depending on your setup, you may wish to ansible's --private-key option to specify a pem file instead)
2012-07-04 23:44:39 +02:00
2012-08-13 20:51:36 +02:00
Now ping all your nodes:
2012-03-09 05:05:52 +01:00
2012-08-13 20:51:36 +02:00
.. code-block :: bash
2012-03-08 19:36:47 +01:00
2012-08-13 20:51:36 +02:00
$ ansible all -m ping
2012-07-04 23:44:39 +02:00
2013-02-02 18:24:48 +01:00
Ansible will attempt to remote connect to the machines using your current
user name, just like SSH would. To override the remote user name, just use the '-u' parameter.
2012-08-31 05:55:31 +02:00
If you would like to access sudo mode, there are also flags to do that:
2012-07-04 23:44:39 +02:00
2012-08-13 20:51:36 +02:00
.. code-block :: bash
# as bruce
$ ansible all -m ping -u bruce
2012-07-04 23:44:39 +02:00
# as bruce, sudoing to root
2012-08-13 20:51:36 +02:00
$ ansible all -m ping -u bruce --sudo
2012-07-04 23:44:39 +02:00
# as bruce, sudoing to batman
2012-08-13 20:51:36 +02:00
$ ansible all -m ping -u bruce --sudo --sudo-user batman
2012-07-04 23:44:39 +02:00
2013-06-19 00:37:02 +02:00
(The sudo implementation is changeable in ansible's configuration file if you happen to want to use a sudo
2013-02-02 18:24:48 +01:00
replacement. Flags passed dot sudo can also be set.)
2012-08-13 20:51:36 +02:00
Now run a live command on all of your nodes:
2012-03-09 05:05:52 +01:00
2012-08-13 20:51:36 +02:00
.. code-block :: bash
$ ansible all -a "/bin/echo hello"
2012-03-09 05:05:52 +01:00
2012-03-09 20:39:29 +01:00
Congratulations. You've just contacted your nodes with Ansible. It's
2013-09-30 01:30:10 +02:00
soon going to be time to read some of the more real-world :doc: `intro_adhoc` , and explore
2012-03-09 20:39:29 +01:00
what you can do with different modules, as well as the Ansible
2012-03-18 17:55:18 +01:00
:doc: `playbooks` language. Ansible is not just about running commands, it
also has powerful configuration management and deployment features. There's more to
explore, but you already have a fully working infrastructure!
2012-03-08 19:36:47 +01:00
2013-10-05 00:14:54 +02:00
.. _a_note_about_host_key_checking:
2013-07-05 00:51:47 +02:00
A note about Host Key Checking
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
Ansible 1.2.1 and later have host key checking enabled by default.
2013-09-29 19:29:11 +02:00
If a host is reinstalled and has a different key in 'known_hosts', this will result in a error message until corrected. If a host is not initially in 'known_hosts' this will result in prompting for confirmation of the key, which results in a interactive experience if using Ansible, from say, cron.
2013-07-05 00:51:47 +02:00
If you wish to disable this behavior and understand the implications, you can do so by editing /etc/ansible/ansible.cfg or ~/.ansible.cfg::
2013-07-19 07:26:30 +02:00
[defaults]
2013-07-05 00:51:47 +02:00
host_key_checking = False
2013-07-05 00:56:46 +02:00
Alternatively this can be set by an environment variable:
$ export ANSIBLE_HOST_KEY_CHECKING=False
2013-09-29 19:29:11 +02:00
Also note that host key checking in paramiko mode is reasonably slow, therefore switching to 'ssh' is also recommended when using this feature.
2012-03-09 20:39:29 +01:00
.. seealso ::
2013-10-03 03:45:57 +02:00
:doc: `intro_inventory`
More information about inventory
2013-09-30 02:09:30 +02:00
:doc: `intro_adhoc`
2012-03-11 20:34:21 +01:00
Examples of basic commands
:doc: `playbooks`
Learning ansible's configuration management language
2012-03-31 15:55:37 +02:00
`Mailing List <http://groups.google.com/group/ansible-project> `_
Questions? Help? Ideas? Stop by the list on Google Groups
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel
2012-03-11 20:34:21 +01:00