2013-04-15 01:31:47 +02:00
Frequently Asked Questions
==========================
Here are some commonly-asked questions and their answers.
2015-04-13 21:21:08 +02:00
.. _set_environment:
2013-10-04 19:27:19 +02:00
2015-04-13 21:21:08 +02:00
How can I set the PATH or any other environment variable for a task or entire playbook?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-08-20 01:28:50 +02:00
Setting environment variables can be done with the `environment` keyword. It can be used at task or play level::
2015-04-13 21:21:08 +02:00
environment:
2015-06-24 02:48:13 +02:00
PATH: "{{ ansible_env.PATH }}:/thingy/bin"
2015-04-13 21:21:08 +02:00
SOME: value
2014-09-03 03:48:01 +02:00
2013-04-15 01:31:47 +02:00
How do I handle different machines needing different user accounts or ports to log in with?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Setting inventory variables in the inventory file is the easiest way.
For instance, suppose these hosts have different usernames and ports::
[webservers]
asdf.example.com ansible_ssh_port=5000 ansible_ssh_user=alice
jkl.example.com ansible_ssh_port=5001 ansible_ssh_user=bob
You can also dictate the connection type to be used, if you want::
[testcluster]
localhost ansible_connection=local
/path/to/chroot1 ansible_connection=chroot
foo.example.com
bar.example.com
You may also wish to keep these in group variables instead, or file in them in a group_vars/<groupname> file.
See the rest of the documentation for more information about how to organize variables.
2013-10-04 19:27:19 +02:00
.. _use_ssh:
2013-04-15 01:31:47 +02:00
How do I get ansible to reuse connections, enable Kerberized SSH, or have Ansible pay attention to my local SSH config file?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2013-07-20 18:44:15 +02:00
Switch your default connection type in the configuration file to 'ssh', or use '-c ssh' to use
2013-07-05 01:10:28 +02:00
Native OpenSSH for connections instead of the python paramiko library. In Ansible 1.2.1 and later, 'ssh' will be used
by default if OpenSSH is new enough to support ControlPersist as an option.
2013-04-15 01:31:47 +02:00
Paramiko is great for starting out, but the OpenSSH type offers many advanced options. You will want to run Ansible
from a machine new enough to support ControlPersist, if you are using this connection type. You can still manage
2013-04-26 11:08:13 +02:00
older clients. If you are using RHEL 6, CentOS 6, SLES 10 or SLES 11 the version of OpenSSH is still a bit old, so
consider managing from a Fedora or openSUSE client even though you are managing older nodes, or just use paramiko.
2013-04-15 01:31:47 +02:00
We keep paramiko as the default as if you are first installing Ansible on an EL box, it offers a better experience
for new users.
2013-10-04 19:27:19 +02:00
.. _ec2_cloud_performance:
2013-04-15 01:31:47 +02:00
How do I speed up management inside EC2?
++++++++++++++++++++++++++++++++++++++++
Don't try to manage a fleet of EC2 machines from your laptop. Connect to a management node inside EC2 first
and run Ansible from there.
2013-10-04 19:27:19 +02:00
.. _python_interpreters:
2013-04-15 01:31:47 +02:00
How do I handle python pathing not having a Python 2.X in /usr/bin/python on a remote machine?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
While you can write ansible modules in any language, most ansible modules are written in Python, and some of these
are important core ones.
By default Ansible assumes it can find a /usr/bin/python on your remote system that is a 2.X version of Python, specifically
2.4 or higher.
Setting of an inventory variable 'ansible_python_interpreter' on any host will allow Ansible to auto-replace the interpreter
used when executing python modules. Thus, you can point to any python you want on the system if /usr/bin/python on your
system does not point to a Python 2.X interpreter.
Some Linux operating systems, such as Arch, may only have Python 3 installed by default. This is not sufficient and you will
get syntax errors trying to run modules with Python 3. Python 3 is essentially not the same
language as Python 2. Ansible modules currently need to support older Pythons for users that still have Enterprise Linux 5 deployed, so they are not yet ported to run under Python 3.0. This is not a problem though as you can just install Python 2 also on a managed host.
Python 3.0 support will likely be addressed at a later point in time when usage becomes more mainstream.
Do not replace the shebang lines of your python modules. Ansible will do this for you automatically at deploy time.
2013-10-04 19:27:19 +02:00
.. _use_roles:
2013-04-15 01:31:47 +02:00
What is the best way to make content reusable/redistributable?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If you have not done so already, read all about "Roles" in the playbooks documentation. This helps you make playbook content
2014-05-03 17:59:50 +02:00
self-contained, and works well with things like git submodules for sharing content with others.
2013-04-15 01:31:47 +02:00
If some of these plugin types look strange to you, see the API documentation for more details about ways Ansible can be extended.
2013-10-04 19:27:19 +02:00
.. _configuration_file:
2013-04-15 01:31:47 +02:00
Where does the configuration file live and what can I configure in it?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2013-12-21 08:06:38 +01:00
See :doc: `intro_configuration` .
2013-04-15 01:31:47 +02:00
2013-10-04 19:27:19 +02:00
.. _who_would_ever_want_to_disable_cowsay_but_ok_here_is_how:
2013-04-15 01:31:47 +02:00
How do I disable cowsay?
++++++++++++++++++++++++
If cowsay is installed, Ansible takes it upon itself to make your day happier when running playbooks. If you decide
that you would like to work in a professional cow-free environment, you can either uninstall cowsay, or set an environment variable::
export ANSIBLE_NOCOWS=1
2013-10-04 19:27:19 +02:00
.. _browse_facts:
2013-04-15 01:31:47 +02:00
How do I see a list of all of the ansible\_ variables?
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ansible by default gathers "facts" about the machines under management, and these facts can be accessed in Playbooks and in templates. To see a list of all of the facts that are available about a machine, you can run the "setup" module as an ad-hoc action::
ansible -m setup hostname
This will print out a dictionary of all of the facts that are available for that particular host.
2013-10-04 19:27:19 +02:00
.. _host_loops:
2013-04-15 01:31:47 +02:00
How do I loop over a list of hosts in a group, inside of a template?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A pretty common pattern is to iterate over a list of hosts inside of a host group, perhaps to populate a template configuration
file with a list of servers. To do this, you can just access the "$groups" dictionary in your template, like this::
{% for host in groups['db_servers'] %}
{{ host }}
{% endfor %}
If you need to access facts about these hosts, for instance, the IP address of each hostname, you need to make sure that the facts have been populated. For example, make sure you have a play that talks to db_servers::
- hosts: db_servers
tasks:
- # doesn't matter what you do, just that they were talked to previously.
Then you can use the facts inside your template, like this::
{% for host in groups['db_servers'] %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}
2014-01-02 23:37:48 +01:00
.. _programatic_access_to_a_variable:
2013-12-27 21:52:53 +01:00
2014-03-15 15:36:42 +01:00
How do I access a variable name programmatically?
+++++++++++++++++++++++++++++++++++++++++++++++++
2013-12-27 21:52:53 +01:00
An example may come up where we need to get the ipv4 address of an arbitrary interface, where the interface to be used may be supplied
via a role parameter or other input. Variable names can be built by adding strings together, like so::
{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}
2014-03-15 15:36:42 +01:00
The trick about going through hostvars is necessary because it's a dictionary of the entire namespace of variables. 'inventory_hostname'
is a magic variable that indicates the current host you are looping over in the host loop.
2013-12-27 21:52:53 +01:00
2014-01-02 23:37:48 +01:00
.. _first_host_in_a_group:
2013-12-27 21:52:53 +01:00
How do I access a variable of the first host in a group?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What happens if we want the ip address of the first webserver in the webservers group? Well, we can do that too. Note that if we
are using dynamic inventory, which host is the 'first' may not be consistent, so you wouldn't want to do this unless your inventory
2014-01-29 05:41:39 +01:00
was static and predictable. (If you are using :doc: `tower` , it will use database order, so this isn't a problem even if you are using cloud
2013-12-27 21:52:53 +01:00
based inventory scripts).
Anyway, here's the trick::
{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}
Notice how we're pulling out the hostname of the first machine of the webservers group. If you are doing this in a template, you
could use the Jinja2 '#set' directive to simplify this, or in a playbook, you could also use set_fact:
- set_fact: headnode={{ groups[['webservers'][0]] }}
- debug: msg={{ hostvars[headnode].ansible_eth0.ipv4.address }}
Notice how we interchanged the bracket syntax for dots -- that can be done anywhere.
2013-10-04 19:27:19 +02:00
.. _file_recursion:
2013-04-15 01:31:47 +02:00
How do I copy files recursively onto a target host?
+++++++++++++++++++++++++++++++++++++++++++++++++++
2014-03-19 23:05:33 +01:00
The "copy" module has a recursive parameter, though if you want to do something more efficient for a large number of files, take a look at the "synchronize" module instead, which wraps rsync. See the module index for info on both of these modules.
2013-04-15 01:31:47 +02:00
2013-10-04 19:27:19 +02:00
.. _shell_env:
2013-04-15 01:31:47 +02:00
How do I access shell environment variables?
++++++++++++++++++++++++++++++++++++++++++++
If you just need to access existing variables, use the 'env' lookup plugin. For example, to access the value of the HOME
environment variable on management machine::
---
# ...
vars:
local_home: "{{ lookup('env','HOME') }}"
If you need to set environment variables, see the Advanced Playbooks section about environments.
2013-10-04 19:27:19 +02:00
Ansible 1.4 will also make remote environment variables available via facts in the 'ansible_env' variable::
{{ ansible_env.SOME_VARIABLE }}
2013-10-08 14:38:51 +02:00
.. _user_passwords:
How do I generate crypted passwords for the user module?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2014-01-08 02:20:39 +01:00
The mkpasswd utility that is available on most Linux systems is a great option::
2013-10-08 14:38:51 +02:00
2014-01-08 02:20:39 +01:00
mkpasswd --method=SHA-512
If this utility is not installed on your system (e.g. you are using OS X) then you can still easily
generate these passwords using Python. First, ensure that the `Passlib <https://code.google.com/p/passlib/> `_
password hashing library is installed.
pip install passlib
Once the library is ready, SHA512 password values can then be generated as follows::
2014-09-03 13:33:54 +02:00
python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.encrypt(getpass.getpass())"
2013-10-08 14:38:51 +02:00
2013-10-04 19:27:19 +02:00
.. _commercial_support:
2013-07-20 18:44:15 +02:00
Can I get training on Ansible or find commercial support?
2013-04-15 01:31:47 +02:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-08-20 16:00:24 +02:00
Yes! See our `services page <http://www.ansible.com/services> `_ for information on our services and training offerings. Support is also included with :doc: `tower` . Email `info@ansible.com <mailto:info@ansible.com> `_ for further details.
We also offer free web-based training classes on a regular basis. See our `webinar page <http://www.ansible.com/webinars-training> `_ for more info on upcoming webinars.
2013-04-15 01:31:47 +02:00
2013-10-04 19:27:19 +02:00
.. _web_interface:
Is there a web interface / REST API / etc?
++++++++++++++++++++++++++++++++++++++++++
2014-01-28 17:04:34 +01:00
Yes! Ansible, Inc makes a great product that makes Ansible even more powerful
and easy to use. See :doc: `tower` .
2013-10-04 19:27:19 +02:00
.. _docs_contributions:
2013-04-15 01:31:47 +02:00
How do I submit a change to the documentation?
++++++++++++++++++++++++++++++++++++++++++++++
2014-03-04 19:18:34 +01:00
Great question! Documentation for Ansible is kept in the main project git repository, and complete instructions for contributing can be found in the docs README `viewable on GitHub <https://github.com/ansible/ansible/blob/devel/docsite/README.md> `_ . Thanks!
2013-04-15 01:31:47 +02:00
2014-02-27 23:44:21 +01:00
.. _keep_secret_data:
How do I keep secret data in my playbook?
+++++++++++++++++++++++++++++++++++++++++
2014-03-31 01:45:55 +02:00
If you would like to keep secret data in your Ansible content and still share it publicly or keep things in source control, see :doc: `playbooks_vault` .
2014-02-27 23:44:21 +01:00
2013-10-04 19:27:19 +02:00
.. _i_dont_see_my_question:
2014-08-12 19:35:38 +02:00
In Ansible 1.8 and later, if you have a task that you don't want to show the results or command given to it when using -v (verbose) mode, the following task or playbook attribute can be useful::
- name: secret task
shell: /usr/bin/do_something --value={{ secret_value }}
no_log: True
This can be used to keep verbose output but hide sensitive information from others who would otherwise like to be able to see the output.
The no_log attribute can also apply to an entire play::
- hosts: all
no_log: True
Though this will make the play somewhat difficult to debug. It's recommended that this
be applied to single tasks only, once a playbook is completed.
2013-04-15 01:31:47 +02:00
I don't see my question here
++++++++++++++++++++++++++++
2014-01-28 17:04:34 +01:00
Please see the section below for a link to IRC and the Google Group, where you can ask your question there.
2013-04-15 01:31:47 +02:00
2013-10-05 18:31:16 +02:00
.. seealso ::
:doc: `index`
The documentation index
:doc: `playbooks`
An introduction to playbooks
:doc: `playbooks_best_practices`
Best practices advice
2014-05-06 13:07:12 +02:00
`User Mailing List <http://groups.google.com/group/ansible-project> `_
2013-10-05 18:31:16 +02:00
Have a question? Stop by the google group!
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel
2013-04-15 01:31:47 +02:00