Validando versão do ansible
vagrant@ubuntu-bionic ~> ansible-playbook --version
ansible-playbook 2.5.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.15+ (default, Oct 7 2019, 17:39:04) [GCC 7.4.0]
Resultado da execução do playbook
vagrant@ubuntu-bionic ~> ansible-playbook -i /vagrant/configs/ansible/hosts /vagrant/configs/ansible/playbook.yml
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to have been in '/vagrant/configs/ansible/playbook.yml': line 4, column 13, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- hosts: all
handlers:
^ here
Arquivo playbook.yml
O arquivo playbook.yml foi copiado diretamente da aula em questão.
- hosts: all
handlers:
- name: restart mysql
service:
name: mysql
state: restarted
become: yes
tasks:
- name: 'Instalar MySQL Server'
apt:
update_cache: yes
cache_valid_time: 3600 #1 hora
name: ["mysql-server-5.7", "python3-mysqldb"]
state: latest
become: yes
- name: 'Criar usuario no MySQL'
mysql_user:
login_user: root
name: phpuser
password: pass
priv: '*.*:ALL'
host: '%'
state: present
become: yes
- name: 'Copiar arquivo mysqld.cnf'
copy:
src: /vagrant/configs/mysqld.cnf
dest: /etc/mysql/mysql.conf.d/mysqld.cnf
owner: root
group: root
mode: 0644
become: yes
notify:
- restart mysql