diff options
author | sirkubax <muszynski@so1.net> | 2018-05-15 12:03:43 +0200 |
---|---|---|
committer | sirkubax <muszynski@so1.net> | 2018-05-15 12:03:43 +0200 |
commit | 30b7e84f2642dc4182d3c1333ffe14fdaddd6f5b (patch) | |
tree | a2527fa62022649276b23167c4ebfefbeb3e33e0 /ansible.html.markdown | |
parent | 487db1817eead3fe38887e96038606980ad671e8 (diff) |
add example playbook
Diffstat (limited to 'ansible.html.markdown')
-rw-r--r-- | ansible.html.markdown | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/ansible.html.markdown b/ansible.html.markdown index 74195222..d02ca1ce 100644 --- a/ansible.html.markdown +++ b/ansible.html.markdown @@ -6,14 +6,73 @@ contributors: filename: LearnAnsible.txt --- -## Ansible: the easiest orchestration tool - -```yaml --- -"{{ Explanation: Why Ansible and detailed Intro }}" written in the second part of document +"{{ Ansible }}" is an orchestration tool written in Python. ``` +## Example +An example playbook to install apache and configure log level +```yml +--- +- hosts: apache + + vars: + apache2_log_level: "warn" + + handlers: + - name: restart apache + service: + name: apache2 + state: restarted + enabled: True + notify: + - Wait for instances to listen on port 80 + become: True + + - name: reload apache + service: + name: apache2 + state: reloaded + notify: + - Wait for instances to listen on port 80 + become: True + + - name: Wait for instances to listen on port 80 + wait_for: + state: started + host: localhost + port: 80 + timeout: 15 + delay: 5 + + tasks: + - name: Update cache + apt: + update_cache: yes + cache_valid_time: 7200 + become: True + + - name: Install packages + apt: + name={{ item }} + with_items: + - apache2 + - logrotate + notify: + - restart apache + become: True + + - name: Configure apache2 log level + lineinfile: + dest: /etc/apache2/apache2.conf + line: "LogLevel {{ apache2_log_level }}" + regexp: "^LogLevel" + notify: + - reload apache + become: True + +``` ## Installation ```bash @@ -29,7 +88,7 @@ $ apt-get install ansible ### Your first ansible command (shell execution) ```bash -# This command ping the localhost (defined in default inventory /etc/ansible/hosts) +# This command ping the localhost (defined in default inventory: /etc/ansible/hosts) $ ansible -m ping localhost # you should see this output localhost | SUCCESS => { @@ -231,12 +290,15 @@ For now you should know that CLI variables have the top priority. You should also know, that a nice way to pool some data is a **lookup** ### Lookups +Awesome tool to query data from various sources!!! Awesome! query from: -* pipe +* pipe (load shell command output into variable!) * file * stream * etcd +* password management tools +* url ```bash # read playbooks/lookup.yml |