DevOps Tools/Configuration/Ansible/Playbook Examples
From r00tedvw.com wiki
(Difference between revisions)
Line 25: | Line 25: | ||
~$ ansible-playbook /etc/ansible/playbooks/centos_base_packages.yml</nowiki> | ~$ ansible-playbook /etc/ansible/playbooks/centos_base_packages.yml</nowiki> | ||
+ | |||
+ | ==CentOS - update the hosts file from template== | ||
+ | This uses the '''template'''module and requires that a template already be created. The template can be a plain host file without variables, will be static, and will replace any existing hosts file in place. | ||
+ | <nowiki>~$ sudo cat /etc/ansible/playbooks/hosts.yml | ||
+ | --- | ||
+ | # tasks/hosts.yml | ||
+ | - hosts: centos | ||
+ | tasks: | ||
+ | - name: host file | ||
+ | template: | ||
+ | src: /etc/ansible/playbooks/templates/hosts.j2 | ||
+ | dest: /etc/hosts</nowiki> |
Revision as of 16:35, 31 January 2019
Overview | Continuous Integration (CI) | Source Control Management (SCM) | Containerization | Configuration | Integration
Ansible | Playbook Examples
Playbook Examples
CentOS - ensure certain packages are installed
This uses the yum module
~$ cat /etc/ansible/playbooks/centos_base_packages.yml - hosts: centos tasks: - name: ensure a list of packages installed yum: name: "{{ packages }}" vars: packages: - telnet - net-tools - vim - tcpdump - bind-utils - redhat-lsb-core - wget - nfs-utils - policycoreutils-python - setroubleshoot - setools ~$ ansible-playbook /etc/ansible/playbooks/centos_base_packages.yml
CentOS - update the hosts file from template
This uses the templatemodule and requires that a template already be created. The template can be a plain host file without variables, will be static, and will replace any existing hosts file in place.
~$ sudo cat /etc/ansible/playbooks/hosts.yml --- # tasks/hosts.yml - hosts: centos tasks: - name: host file template: src: /etc/ansible/playbooks/templates/hosts.j2 dest: /etc/hosts