Difference between revisions of "Ansible"
Jump to navigation
Jump to search
(Install, Modules, Best practices) |
|||
Line 18: | Line 18: | ||
# <code>ansible</code> - to execute an individual shell command or Ansible module on the specified systems | # <code>ansible</code> - to execute an individual shell command or Ansible module on the specified systems | ||
# <code>ansible-vault</code> - (optional) to encrypt or decrypt YAML files that Ansible uses. | # <code>ansible-vault</code> - (optional) to encrypt or decrypt YAML files that Ansible uses. | ||
+ | |||
+ | === Global Config === | ||
+ | <code>export ANSIBLE_HOST_KEY_CHECKING=False</code> | ||
+ | or set it in your ~/.ansible.cfg so that as you add new hosts it won't prompt you. | ||
+ | |||
+ | Also [https://docs.ansible.com/ansible/intro_getting_started.html#your-first-commands use 'ssh' instead of paramiko] when doing this. | ||
+ | |||
+ | === Initialize a Project === | ||
+ | '''Ansible Galaxy''' If you want to do a new project, you can use the <code>ansible-galaxy foo init</code> command which will create the directory and file structure for 'foo' in the current working directory. | ||
== Modules == | == Modules == | ||
Line 34: | Line 43: | ||
Note: control verbosity with <code>-vvvv</code> | Note: control verbosity with <code>-vvvv</code> | ||
# <code>ansible -c local -i ~/ansible_hosts -m ping all</code> ping all the hosts in the inventory file | # <code>ansible -c local -i ~/ansible_hosts -m ping all</code> ping all the hosts in the inventory file | ||
− | # <code>ansible -m setup wiki.example.com</code> will show you all the ansible 'facts' (aka [[ansible_variables]]) about that host. | + | # <code>ansible '''-m setup''' wiki.example.com</code> will show you all the ansible 'facts' (aka [[ansible_variables]]) about that host. |
− | # <code>ansible all -m setup -a "filter=ansible_distribution*"</code> use a filter action to see specific variables | + | # <code>ansible '''localhost''' -m setup -a 'gather_subset=!all'</code> or look at the localhost |
+ | # <code>ansible all -m setup -a '''"filter=ansible_distribution*"'''</code> use a filter action to see specific variables | ||
+ | # <code>ansible localhost -m setup --tree /tmp/facts</code> store all facts in a file 'tree', based on hostname | ||
#<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]' | #<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]' | ||
# <code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks | # <code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks | ||
Line 43: | Line 54: | ||
# <code>~/bin/ansible/contrib/inventory/digital_ocean.py --list --pretty --api-token TOKEN_HERE</code> use the DO api to list your droplets (dynamic inventory) | # <code>~/bin/ansible/contrib/inventory/digital_ocean.py --list --pretty --api-token TOKEN_HERE</code> use the DO api to list your droplets (dynamic inventory) | ||
# <code>ansible-playbook -vvv launch.yml -l wiki.example.com --user=root -e do_name=wiki.example.com '''--start-at-task'''='remove empty wiki schema from database if it already exists'</code> start at a particular point in the task list | # <code>ansible-playbook -vvv launch.yml -l wiki.example.com --user=root -e do_name=wiki.example.com '''--start-at-task'''='remove empty wiki schema from database if it already exists'</code> start at a particular point in the task list | ||
+ | # <code>php -r 'var_dump(json_decode(file_get_contents("/tmp/facts/localhost"), true));'</code> look at the json with php (or more interesting tools) With Ansible's Jinja2 filters, you can specify the output of a variable to be 'pretty' <nowiki>{{ some_variable | to_nice_json }}</nowiki> | ||
== Variables == | == Variables == | ||
Line 103: | Line 115: | ||
'''Play''': each play and contained structures, vars entries, include_vars, role defaults and vars. | '''Play''': each play and contained structures, vars entries, include_vars, role defaults and vars. | ||
'''Host''': variables directly associated to a host, like inventory, facts or registered task outputs | '''Host''': variables directly associated to a host, like inventory, facts or registered task outputs | ||
+ | |||
+ | == Ansible with Vagrant == | ||
+ | https://docs.ansible.com/ansible/guide_vagrant.html | ||
== Ansible with MediaWiki == | == Ansible with MediaWiki == |
Revision as of 23:56, 15 September 2016
- ↑ Choosing which host(s) to operate on https://docs.ansible.com/ansible/intro_patterns.html