Ansible: conheça alguns módulos essenciais para automação.

- name: install the latest version of epel-release
yum:
name: epel-release
state: latest
- name: upgrade all packages
yum:
name: '*'
state: latest
update_cache=yes
- name: Copy a file www.conf for server
copy: src=www.conf dest=/etc/php-fpm.d/www.conf owner=root group=root
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
- name: Copy file with owner and permission, using symbolic representation
copy:
src: /home/myfiles/users.conf
dest: /etc/users.conf
owner: root
group: root
mode: u=rw,g=r,o=r
- name: Create directory /var/www/html
file: path={{item}} state=directory mode=0755 owner=nginx group=nginx
with_items:
- /var/www
- /var/www/html
notify: Restart nginx
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
- name: Create directory used by PHP-FPM
file: path={{item}} state=directory mode=755 owner=nginx group=nginx
with_items:
- /var/lib/php/session
- /var/lib/php/wsdlcache
notify: Restart php-fpm
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
- name: Backup a file /etc/nginx
command: mv /etc/nginx /etc/nginx_original
args:
warn: false
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
- name: Execute the Uptime command
command: "uptime"
- name: Install a list of packages
apt:
name: "{{ packages }}"
vars:
packages:
- vim
- git
- name: Upgrade all packages to the latest version
apt:
name: "*"
state: latest
- name: Disable SELinux
selinux:
state: disabled
- name: Enable SELinux
selinux:
policy: targeted
state: enforcing
ss- name: restarting PHP service
systemd:
name: php-fpm
state: restarted
daemon_reload=yes
enable=yes
- name: enable service nginx
systemd:
name: nginx
enabled: yes
- ec2:
key_name: banco
instance_type: t2.micro
image: ami-123456
wait: yes
group: database
count: 3
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
- ec2:
key_name: banco
group: database
instance_type: c3.medium
image: ami-123456
wait: yes
wait_timeout: 500
volumes:
- device_name: /dev/xvda
volume_type: gp2
volume_size: 8
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
count_tag:
Name: dbserver
exact_count: 1
- name: Extract commands.tgz into /var/lib/commands
unarchive:
src: commands.tgz
dest: /var/lib/commands
- name: Unarchive a file that is already on the remote machine
unarchive:
src: /tmp/arquivo.zip
dest: /usr/local/bin
remote_src: yes

Passion for DevOps