Difference between revisions of "IT-SDK-Ansible"
Jump to navigation
Jump to search
(Created page with "==Kostenlose Kurse== * Ansible: https://www.redhat.com/de/services/training/do007-ansible-essentials-simplicity-automation-technical-overview?sc_cid=701f2000001OQFsAAO") |
Samerhijazi (talk | contribs) (→Modules) |
||
| (29 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | == | + | =Ref.= |
| − | * | + | *https://linuxhint.com/category/ansible/ |
| + | *https://www.youtube.com/watch?v=1id6ERvfozo | ||
| + | *https://www.redhat.com/en/services/training/do007-ansible-essentials-simplicity-automation-technical-overview | ||
| + | *https://www.digitalocean.com/community/tutorials/configuration-management-101-writing-ansible-playbooks | ||
| + | *https://opensource.com/article/21/9/ansible-rest-apis | ||
| + | |||
| + | =Modules= | ||
| + | *https://docs.ansible.com/ansible/latest/reference_appendices/logging.html | ||
| + | *https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html | ||
| + | *https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html | ||
| + | *https://docs.ansible.com/ansible/latest/collections/ansible/builtin/index.html | ||
| + | *https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html | ||
| + | *https://docs.ansible.com/ansible/latest/collections/community/general/java_cert_module.html | ||
| + | *https://docs.ansible.com/ansible/latest/collections/community/general/java_keystore_module.html | ||
| + | *https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html ('''Interacts with webservices''') | ||
| + | |||
| + | =Notes= | ||
| + | * Ansible: playbooks, roles, variables, basic modules | ||
| + | =Commands= | ||
| + | <pre class="code"> | ||
| + | ansible $PATTERN -m $MODULE -a "$MODULE_OPTIONS" ## AD_HOC | ||
| + | ... | ||
| + | ansible -m command -a "ls" all | ||
| + | ... | ||
| + | ansible-playbook playbook.yml ## execute the playbook | ||
| + | ansible-playbook playbook.yml --connection=local | ||
| + | </pre> | ||
| + | |||
| + | =Inventory= | ||
| + | * Lists which hosts will receive commands from the control host. | ||
| + | * Location for the inventory file: /etc/ansible/hosts | ||
| + | <pre class="code"> | ||
| + | ansible all --list-hosts | ||
| + | nano inventory | ||
| + | ------------------------------ | ||
| + | [webservers] | ||
| + | 192.0.2.0 | ||
| + | 192.0.2.1 | ||
| + | [databases] | ||
| + | 192.0.2.3 ansible_user=root | ||
| + | ------------------------------ | ||
| + | </pre> | ||
| + | |||
| + | =Playbook= | ||
| + | <pre class="code"> | ||
| + | --- | ||
| + | - name: this playbook will install httpd ## Name of the Play | ||
| + | hosts: web ## In which Host shall the play executed. | ||
| + | vars: ## Definition von Variables | ||
| + | pkgname: httpd | ||
| + | tasks: ## Tasks in this play | ||
| + | - name: Install latest of Apache ## Name of the Task | ||
| + | become: ture ## Execute this Task as "sudo dnf install httpd" | ||
| + | become_user: weblogic ## Exceute this task as "sudo -u weblogic dnf install httpd" | ||
| + | dnf: ## Name of the Modul used (etc. command, apt, user, service ) | ||
| + | name: {{ pkgname }} ## Parameter used form modul | ||
| + | state: latest ## Parameter used form modul | ||
| + | </pre> | ||
| + | |||
| + | =Playbook-Localhost= | ||
| + | <pre class="code"> | ||
| + | ansible-playbook playbook.yml --connection=local 127.0.0.1 # using Ansible command line | ||
| + | -------------------------------------------------------------# using inventory | ||
| + | 127.0.0.1 ansible_connection=local | ||
| + | -------------------------------------------------------------# using Ansible configuration file | ||
| + | [defaults] | ||
| + | transport = local | ||
| + | -------------------------------------------------------------# using playbook header | ||
| + | - hosts: localhost 127.0.0.1 | ||
| + | connection: local | ||
| + | </pre> | ||
Latest revision as of 16:51, 6 April 2022
Ref.
- https://linuxhint.com/category/ansible/
- https://www.youtube.com/watch?v=1id6ERvfozo
- https://www.redhat.com/en/services/training/do007-ansible-essentials-simplicity-automation-technical-overview
- https://www.digitalocean.com/community/tutorials/configuration-management-101-writing-ansible-playbooks
- https://opensource.com/article/21/9/ansible-rest-apis
Modules
- https://docs.ansible.com/ansible/latest/reference_appendices/logging.html
- https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html
- https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html
- https://docs.ansible.com/ansible/latest/collections/ansible/builtin/index.html
- https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html
- https://docs.ansible.com/ansible/latest/collections/community/general/java_cert_module.html
- https://docs.ansible.com/ansible/latest/collections/community/general/java_keystore_module.html
- https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html (Interacts with webservices)
Notes
- Ansible: playbooks, roles, variables, basic modules
Commands
ansible $PATTERN -m $MODULE -a "$MODULE_OPTIONS" ## AD_HOC ... ansible -m command -a "ls" all ... ansible-playbook playbook.yml ## execute the playbook ansible-playbook playbook.yml --connection=local
Inventory
- Lists which hosts will receive commands from the control host.
- Location for the inventory file: /etc/ansible/hosts
ansible all --list-hosts nano inventory ------------------------------ [webservers] 192.0.2.0 192.0.2.1 [databases] 192.0.2.3 ansible_user=root ------------------------------
Playbook
---
- name: this playbook will install httpd ## Name of the Play
hosts: web ## In which Host shall the play executed.
vars: ## Definition von Variables
pkgname: httpd
tasks: ## Tasks in this play
- name: Install latest of Apache ## Name of the Task
become: ture ## Execute this Task as "sudo dnf install httpd"
become_user: weblogic ## Exceute this task as "sudo -u weblogic dnf install httpd"
dnf: ## Name of the Modul used (etc. command, apt, user, service )
name: {{ pkgname }} ## Parameter used form modul
state: latest ## Parameter used form modul
Playbook-Localhost
ansible-playbook playbook.yml --connection=local 127.0.0.1 # using Ansible command line -------------------------------------------------------------# using inventory 127.0.0.1 ansible_connection=local -------------------------------------------------------------# using Ansible configuration file [defaults] transport = local -------------------------------------------------------------# using playbook header - hosts: localhost 127.0.0.1 connection: local