DevOps Tools/Configuration/Ansible/Playbook Examples
From r00tedvw.com wiki
(Difference between revisions)
(4 intermediate revisions by one user not shown) | |||
Line 4: | Line 4: | ||
==CentOS - ensure certain packages are installed== | ==CentOS - ensure certain packages are installed== | ||
This uses the '''yum''' module | This uses the '''yum''' module | ||
− | <nowiki>~$ cat /etc/ansible/playbooks/centos_base_packages.yml | + | <nowiki>~$ sudo cat /etc/ansible/playbooks/centos_base_packages.yml |
- hosts: centos | - hosts: centos | ||
tasks: | tasks: | ||
Line 27: | Line 27: | ||
==CentOS - update the hosts file from template== | ==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. | + | 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 | <nowiki>~$ sudo cat /etc/ansible/playbooks/hosts.yml | ||
− | |||
− | |||
- hosts: centos | - hosts: centos | ||
tasks: | tasks: | ||
- name: host file | - name: host file | ||
template: | template: | ||
− | src: /etc/ansible | + | src: /etc/ansible/templates/hosts.j2 |
dest: /etc/hosts</nowiki> | dest: /etc/hosts</nowiki> | ||
+ | |||
+ | ==Linux - Set the permissions for all files and folders within a directory recursively== | ||
+ | This uses the '''file''' module. It should be noted that while it will set the execution bit on directories (if there is none), it will not do so on files '''UNLESS''' at least (1) execution bit is already set. | ||
+ | <nowiki>$ cat /etc/ansible/playbooks/ansible_permissions.yml | ||
+ | - hosts: ansible | ||
+ | tasks: | ||
+ | - name: ansible permissions | ||
+ | file: | ||
+ | #state: directory | ||
+ | path: /etc/ansible | ||
+ | owner: root | ||
+ | group: root | ||
+ | mode: u=rwX,g=rX,o=rX | ||
+ | recurse: yes</nowiki> |
Latest revision as of 18:09, 31 January 2019
Overview | Continuous Integration (CI) | Source Control Management (SCM) | Containerization | Configuration | Integration
Ansible | Playbook Examples
Contents |
[edit] Playbook Examples
[edit] CentOS - ensure certain packages are installed
This uses the yum module
~$ sudo 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
[edit] 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.
~$ sudo cat /etc/ansible/playbooks/hosts.yml - hosts: centos tasks: - name: host file template: src: /etc/ansible/templates/hosts.j2 dest: /etc/hosts
[edit] Linux - Set the permissions for all files and folders within a directory recursively
This uses the file module. It should be noted that while it will set the execution bit on directories (if there is none), it will not do so on files UNLESS at least (1) execution bit is already set.
$ cat /etc/ansible/playbooks/ansible_permissions.yml - hosts: ansible tasks: - name: ansible permissions file: #state: directory path: /etc/ansible owner: root group: root mode: u=rwX,g=rX,o=rX recurse: yes