Ansible: Tasks 101 
More crap will be added to this post sometime in the future, stay tuned if you want...

-Angel

[acool@hydra2 ansible]$ # running a playbook
[acool@hydra2 ansible]$ ansible-playbook dev-hosts-playbook.yml -i dev-hosts.txt
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$# content of dev-hosts.txt
[acool@hydra2 ansible]$ cat dev-hosts.txt
acool2.10-network.net ansible_user=root
userA_2.10-network.net ansible_user=root
userB_2.10-network.net ansible_user=root
userC_2.10-network.net ansible_user=root


[acool@hydra2 ansible]$
[acool@hydra2 ansible]$ # playbook content
[acool@hydra2 ansible]$ cat dev-hosts-playbook.yml
---
- hosts: all
tasks:
- name: Installing EPEL repo.
yum: pkg=epel-release.noarch state=installed
- name : Installing RPMs
yum: pkg={{item}} state=installed
with_items:
- centos-release-scl
- centos-release-scl-rh
- rh-php70
- rh-php70-php-mysqlnd
- rh-php70-php-bcmath
- rh-php70-php-gd
- rh-php70-php-soap
- rh-php70-php-mbstring
- rh-php70-php-fpm
- sclo-php70-php-pecl-memcached
- git
#- rabbitmq-server
- openvpn
- nginx
- composer
- memcached
- npm
- http-parser
- name: Open firewall ports
firewalld:
port: "{{item.port}}/tcp"
zone: public
permanent: true
state: enabled
immediate: yes
with_items:
- { port: '80' }
- { port: '443' }
- name: Starting services.
action: service name={{item}} state=started enabled=yes
with_items:
- nginx
- memcached
- rh-php70-php-fpm
- name: Enabling php 7
copy:
src: /home/acool/ansible/files/dev-vms/rh-php70.sh
dest: /etc/profile.d/rh-php70.sh
- name: Setting SELINUX to permissive.
selinux:
policy: targeted
state: permissive
- name: Copying nginx config files
template:
src: /home/acool/ansible/templates/dev-vms/10-network-net.conf
dest: /etc/nginx/conf.d/10-network-net.conf
- name: Installing gulp globally.
command: npm install gulp -g
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$ # Ad-Hoc commands, -i stands for inventory and -l for limit
[acool@hydra2 ansible]$ ansible all -i dev-hosts.txt -a 'free -h' -l acool2.10-network.net
acool2.10-network.net | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 1.8G 142M 1.5G 8.6M 165M 1.5G
Swap: 2.0G 0B 2.0G

[acool@hydra2 ansible]$
[acool@hydra2 ansible]$



9/1/2018 - more stuff :)
[aesteban@localhost ansible]$ ## adding a new role
[aesteban@localhost ansible]$ ansible-galaxy init roles/dev --offline
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ll roles/
total 16
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 13:04 app
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 11:17 cms
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 11:10 common
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 13:04 dev
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ls -l
total 32
-rw-rw-r-- 1 aesteban aesteban 62 Sep 1 12:43 app-machines.yml
-rw-rw-r-- 1 aesteban aesteban 62 Sep 1 12:43 cms-machines.yml
-rw-rw-r-- 1 aesteban aesteban 70 Sep 1 16:24 dev-machines.yml
drwxrwxr-x 2 aesteban aesteban 4096 Sep 1 12:48 files
-rw-rw-r-- 1 aesteban aesteban 65 Sep 1 16:19 hosts.txt
drwxrwxr-x 6 aesteban aesteban 4096 Sep 1 13:04 roles
drwxrwxr-x 2 aesteban aesteban 4096 Sep 1 11:10 templates
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible-playbook -i hosts.txt dev-machines.yml --check --limit "dev3.example.com"
...
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ cat hosts.txt
[devmachines]
dev3.example.com

[cmsmachines]

[appmachies]
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible --version
ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.13 (default, May 10 2017, 20:04:36) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible-playbook -i hosts.txt dev-machines.yml --syntax-check

playbook: dev-machines.yml
[aesteban@localhost ansible]$


[ view entry ] ( 1425 views )   |  print article

<<First <Back | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Next> Last>>



2025 By Angel Cool