mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
7.2 KiB
ReStructuredText
150 lines
7.2 KiB
ReStructuredText
13 years ago
|
Getting Started
|
||
|
===============
|
||
13 years ago
|
|
||
11 years ago
|
.. contents:: Topics
|
||
|
|
||
11 years ago
|
.. _gs_about:
|
||
|
|
||
11 years ago
|
Foreword
|
||
|
````````
|
||
13 years ago
|
|
||
11 years ago
|
Now that you've read :doc:`intro_installation` and installed Ansible, it's time to dig in and get
|
||
11 years ago
|
started with some commands.
|
||
13 years ago
|
|
||
10 years ago
|
What we are showing first are not the powerful configuration/deployment/orchestration features of Ansible.
|
||
|
These features are handled by playbooks which are covered in a separate section.
|
||
11 years ago
|
|
||
10 years ago
|
This section is about how to initially get going. Once you have these concepts down, read :doc:`intro_adhoc` for some more
|
||
11 years ago
|
detail, and then you'll be ready to dive into playbooks and explore the most interesting parts!
|
||
11 years ago
|
|
||
11 years ago
|
.. _remote_connection_information:
|
||
|
|
||
11 years ago
|
Remote Connection Information
|
||
|
`````````````````````````````
|
||
13 years ago
|
|
||
10 years ago
|
Before we get started, it's important to understand how Ansible communicates with remote
|
||
11 years ago
|
machines over SSH.
|
||
13 years ago
|
|
||
11 years ago
|
By default, Ansible 1.3 and later will try to use native
|
||
8 years ago
|
OpenSSH for remote communication when possible. This enables ControlPersist (a performance feature), Kerberos, and options in ``~/.ssh/config`` such as Jump Host setup. However, when using Enterprise Linux 6 operating systems as the control machine (Red Hat Enterprise Linux and derivatives such as CentOS), the version of OpenSSH may be too old to support ControlPersist. On these operating systems, Ansible will fallback into using a high-quality Python implementation of
|
||
11 years ago
|
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 -- or engage 'accelerated mode' in Ansible. See :doc:`playbooks_acceleration`.
|
||
13 years ago
|
|
||
8 years ago
|
In releases up to and including Ansible 1.2, the default was strictly paramiko. Native SSH had to be explicitly selected with the ``-c`` ssh option or set in the configuration file.
|
||
12 years ago
|
|
||
10 years ago
|
Occasionally you'll encounter a device that doesn't support SFTP. This is rare, but should it occur, you can switch to SCP mode in :doc:`intro_configuration`.
|
||
13 years ago
|
|
||
9 years ago
|
When speaking with remote machines, Ansible by default assumes you are using SSH keys. SSH keys are encouraged but password authentication can also be used where needed by supplying the option ``--ask-pass``. If using sudo features and when sudo requires a password, also supply ``--ask-become-pass`` (previously ``--ask-sudo-pass`` which has been deprecated).
|
||
12 years ago
|
|
||
10 years ago
|
While it may be common sense, it is worth sharing: Any management system benefits from being run near the machines being managed. If you are running Ansible in a cloud, consider running it from a machine inside that cloud. In most cases this will work better than on the open Internet.
|
||
13 years ago
|
|
||
11 years ago
|
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.
|
||
12 years ago
|
|
||
11 years ago
|
.. _your_first_commands:
|
||
|
|
||
13 years ago
|
Your first commands
|
||
|
```````````````````
|
||
|
|
||
11 years ago
|
Now that you've installed Ansible, it's time to get started with some basics.
|
||
13 years ago
|
|
||
8 years ago
|
Edit (or create) ``/etc/ansible/hosts`` and put one or more remote systems in it. Your
|
||
10 years ago
|
public SSH key should be located in ``authorized_keys`` on those systems::
|
||
13 years ago
|
|
||
8 years ago
|
192.0.2.50
|
||
13 years ago
|
aserver.example.org
|
||
|
bserver.example.org
|
||
|
|
||
11 years ago
|
This is an inventory file, which is also explained in greater depth here: :doc:`intro_inventory`.
|
||
11 years ago
|
|
||
11 years ago
|
We'll assume you are using SSH keys for authentication. To set up SSH agent to avoid retyping passwords, you can
|
||
11 years ago
|
do:
|
||
13 years ago
|
|
||
12 years ago
|
.. code-block:: bash
|
||
|
|
||
|
$ ssh-agent bash
|
||
|
$ ssh-add ~/.ssh/id_rsa
|
||
13 years ago
|
|
||
11 years ago
|
(Depending on your setup, you may wish to use Ansible's ``--private-key`` option to specify a pem file instead)
|
||
13 years ago
|
|
||
12 years ago
|
Now ping all your nodes:
|
||
13 years ago
|
|
||
12 years ago
|
.. code-block:: bash
|
||
13 years ago
|
|
||
12 years ago
|
$ ansible all -m ping
|
||
13 years ago
|
|
||
12 years ago
|
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.
|
||
12 years ago
|
|
||
|
If you would like to access sudo mode, there are also flags to do that:
|
||
13 years ago
|
|
||
12 years ago
|
.. code-block:: bash
|
||
|
|
||
|
# as bruce
|
||
|
$ ansible all -m ping -u bruce
|
||
13 years ago
|
# as bruce, sudoing to root
|
||
12 years ago
|
$ ansible all -m ping -u bruce --sudo
|
||
13 years ago
|
# as bruce, sudoing to batman
|
||
12 years ago
|
$ ansible all -m ping -u bruce --sudo --sudo-user batman
|
||
13 years ago
|
|
||
9 years ago
|
# With latest version of ansible `sudo` is deprecated so use become
|
||
|
# as bruce, sudoing to root
|
||
|
$ ansible all -m ping -u bruce -b
|
||
|
# as bruce, sudoing to batman
|
||
|
$ ansible all -m ping -u bruce -b --become-user batman
|
||
|
|
||
11 years ago
|
(The sudo implementation is changeable in Ansible's configuration file if you happen to want to use a sudo
|
||
11 years ago
|
replacement. Flags passed to sudo (like -H) can also be set there.)
|
||
12 years ago
|
|
||
12 years ago
|
Now run a live command on all of your nodes:
|
||
13 years ago
|
|
||
12 years ago
|
.. code-block:: bash
|
||
|
|
||
|
$ ansible all -a "/bin/echo hello"
|
||
13 years ago
|
|
||
10 years ago
|
Congratulations! You've just contacted your nodes with Ansible. It's
|
||
|
soon going to be time to: read about some more real-world cases in :doc:`intro_adhoc`,
|
||
|
explore what you can do with different modules, and to learn about the Ansible
|
||
13 years ago
|
: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!
|
||
13 years ago
|
|
||
11 years ago
|
.. _a_note_about_host_key_checking:
|
||
|
|
||
11 years ago
|
Host Key Checking
|
||
|
`````````````````
|
||
12 years ago
|
|
||
|
Ansible 1.2.1 and later have host key checking enabled by default.
|
||
|
|
||
11 years ago
|
If a host is reinstalled and has a different key in 'known_hosts', this will result in an 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 an interactive experience if using Ansible, from say, cron. You might not want this.
|
||
12 years ago
|
|
||
8 years ago
|
If you understand the implications and wish to disable this behavior, you can do so by editing ``/etc/ansible/ansible.cfg`` or ``~/.ansible.cfg``::
|
||
12 years ago
|
|
||
12 years ago
|
[defaults]
|
||
12 years ago
|
host_key_checking = False
|
||
|
|
||
12 years ago
|
Alternatively this can be set by an environment variable:
|
||
|
|
||
11 years ago
|
.. code-block:: bash
|
||
|
|
||
12 years ago
|
$ export ANSIBLE_HOST_KEY_CHECKING=False
|
||
|
|
||
11 years ago
|
Also note that host key checking in paramiko mode is reasonably slow, therefore switching to 'ssh' is also recommended when using this feature.
|
||
13 years ago
|
|
||
11 years ago
|
.. _a_note_about_logging:
|
||
|
|
||
10 years ago
|
Ansible will log some information about module arguments on the remote system in the remote syslog, unless a task or play is marked with a "no_log: True" attribute. This is explained later.
|
||
10 years ago
|
|
||
|
To enable basic logging on the control machine see :doc:`intro_configuration` document and set the 'log_path' configuration file setting. Enterprise users may also be interested in :doc:`tower`. Tower provides a very robust database logging feature where it is possible to drill down and see history based on hosts, projects, and particular inventories over time -- explorable both graphically and through a REST API.
|
||
11 years ago
|
|
||
13 years ago
|
.. seealso::
|
||
|
|
||
11 years ago
|
:doc:`intro_inventory`
|
||
|
More information about inventory
|
||
11 years ago
|
:doc:`intro_adhoc`
|
||
13 years ago
|
Examples of basic commands
|
||
|
:doc:`playbooks`
|
||
11 years ago
|
Learning Ansible's configuration management language
|
||
13 years ago
|
`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
|