intro_getting_started.rst 6.81 KB
Newer Older
1 2
Getting Started
===============
Tim Bielawa committed
3

4 5
.. contents:: Topics

6 7
.. _gs_about:

8 9
Foreword
````````
Michael DeHaan committed
10

Michael DeHaan committed
11
Now that you've read :doc:`intro_installation` and installed Ansible, it's time to dig in and get
12
started with some commands.  
Michael DeHaan committed
13

14
What we are showing first are not the powerful configuration/deployment/orchestration of Ansible, called playbooks.
15
Playbooks are covered in a separate section.
16

Michael DeHaan committed
17 18
This section is about how to get going initially.  Once you have these concepts down, read :doc:`intro_adhoc` for some more
detail, and then you'll be ready to dive into playbooks and explore the most interesting parts!
19

20 21
.. _remote_connection_information:

22 23
Remote Connection Information
`````````````````````````````
24

25 26
Before we get started, it's important to understand how Ansible is communicating with remote
machines over SSH. 
Michael DeHaan committed
27

28
By default, Ansible 1.3 and later will try to use native 
Michael DeHaan committed
29 30
OpenSSH for remote communication  when possible.  This enables both ControlPersist (a performance feature), Kerberos, 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 -- or engage 'accelerated mode' in Ansible.  See :doc:`playbooks_acceleration`.
Michael DeHaan committed
31

32
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.
33

Michael DeHaan committed
34
Occasionally you'll encounter a device that doesn't do SFTP. This is rare, but if talking with some remote devices that don't support SFTP, you can switch to SCP mode in :doc:`intro_configuration`.
Michael DeHaan committed
35

Michael DeHaan committed
36
When speaking with remote machines, Ansible will by default assume you are using SSH keys -- which we encourage -- but passwords are fine too.  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.
37

Michael DeHaan committed
38 39
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, consider running Ansible from a machine inside that cloud.  It will work better than on the open
intranet in most cases.
Michael DeHaan committed
40

41
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.
42

43 44
.. _your_first_commands:

Michael DeHaan committed
45 46 47
Your first commands
```````````````````

48
Now that you've installed Ansible, it's time to get started with some basics.
49

50
Edit (or create) /etc/ansible/hosts and put one or more remote systems in it, for
51
which you have your SSH key in ``authorized_keys``::
Michael DeHaan committed
52 53 54 55 56

    192.168.1.50
    aserver.example.org
    bserver.example.org

Michael DeHaan committed
57
This is an inventory file, which is also explained in greater depth here:  :doc:`intro_inventory`.
58

Michael DeHaan committed
59
We'll assume you are using SSH keys for authentication.  To set up SSH agent to avoid retyping passwords, you can
60
do:
Michael DeHaan committed
61

62 63 64 65
.. code-block:: bash

    $ ssh-agent bash
    $ ssh-add ~/.ssh/id_rsa
66

67
(Depending on your setup, you may wish to use Ansible's --private-key option to specify a pem file instead)
68

69
Now ping all your nodes:
70

71
.. code-block:: bash
Michael DeHaan committed
72

73
   $ ansible all -m ping
74

75 76
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.
77 78

If you would like to access sudo mode, there are also flags to do that:
79

80 81 82 83
.. code-block:: bash

    # as bruce
    $ ansible all -m ping -u bruce
84
    # as bruce, sudoing to root
85
    $ ansible all -m ping -u bruce --sudo 
86
    # as bruce, sudoing to batman
87
    $ ansible all -m ping -u bruce --sudo --sudo-user batman
88

89
(The sudo implementation is changeable in Ansible's configuration file if you happen to want to use a sudo
Michael DeHaan committed
90
replacement.  Flags passed to sudo (like -H) can also be set there.)
91

92
Now run a live command on all of your nodes:
93
  
94 95 96
.. code-block:: bash

   $ ansible all -a "/bin/echo hello"
97

98
Congratulations.  You've just contacted your nodes with Ansible.  It's
99
soon going to be time to read some of the more real-world :doc:`intro_adhoc`, and explore
100
what you can do with different modules, as well as the Ansible
101 102 103
: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!
Michael DeHaan committed
104

105 106
.. _a_note_about_host_key_checking:

107 108
Host Key Checking
`````````````````
109 110 111

Ansible 1.2.1 and later have host key checking enabled by default.  

Michael DeHaan committed
112
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.  You might not want this.
113 114 115

If you wish to disable this behavior and understand the implications, you can do so by editing /etc/ansible/ansible.cfg or ~/.ansible.cfg::

116
    [defaults]
117 118
    host_key_checking = False

119 120
Alternatively this can be set by an environment variable:

121 122
.. code-block:: bash

123 124
    $ export ANSIBLE_HOST_KEY_CHECKING=False

125
Also note that host key checking in paramiko mode is reasonably slow, therefore switching to 'ssh' is also recommended when using this feature.
126

127 128 129 130 131
.. _a_note_about_logging:

Ansible will log some information about module arguments on the remote system in the remote syslog.  To enable basic
logging on the control machine see `intro_config` document and set the 'log_path' configuration file setting.  Enterprise users may also be interested in `AnsibleWorks AWX <http://ansibleworks.com/ansibleworks-awx>`_.  AWX 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.

132 133
.. seealso::

134 135
   :doc:`intro_inventory`
       More information about inventory
136
   :doc:`intro_adhoc`
137 138
       Examples of basic commands
   :doc:`playbooks`
139
       Learning Ansible's configuration management language
140 141 142 143
   `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
144