Ao executar o playbook para de acordo com a linha abaixo, recebi um erro o qual não consigo resolver. Fatos: -Antes de substituir pelas variáveis estava Ok -Deu erro de ip host mas add na linha do playbook.
erro:
wordpress_com_ansible % ansible-playbook -i 746-aula1/hosts --extra-vars 'wp_host_ip=172.17.177.40 wp_db_ip=172.17.177.42' 746-aula5/provisioning.yml
PLAY [database] **
TASK [Gathering Facts] *** ok: [172.17.177.42]
TASK [Instala pacotes de dependencia do sistema operacional] * ok: [172.17.177.42]
TASK [Cria o banco no MySQL] * ok: [172.17.177.42]
TASK [Cria o usuário no MySQL] *** fatal: [172.17.177.42]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'wp_username' is undefined\n\nThe error appears to be in '/Users/anderson/wordpress_com_ansible/746-aula5/provisioning.yml': line 23, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n state: present\n - name: 'Cria o usuário no MySQL'\n ^ here\n"}
PLAY RECAP ***
172.17.177.42 : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Código:
---
- hosts: database
handlers:
- name: restart mysqld
service:
name: mysql
state: restarted
become: yes
tasks:
- name: 'Instala pacotes de dependencia do sistema operacional'
apt:
name: ['mysql-server-5.6', 'python-mysqldb']
state: latest
become: yes
- name: 'Cria o banco no MySQL'
mysql_db:
name: wordpress_db
login_user: root
state: present
- name: 'Cria o usuário no MySQL'
mysql_user:
login_user: root
name: "{{ wp_username }}"
password: "{{ wp_user_password }}"
priv: "{{ wp_db_name }}.*:ALL"
state: present
host: "{{ item }}"
with_items:
- 'localhost'
- '127.0.0.1'
- '{{ wp_host_ip }}'
- name: 'Configura MySQL para aceitar conexões remotas'
copy:
src: '/Users/anderson/wordpress_com_ansible/my.cnf'
dest: '/etc/mysql/my.cnf'
become: yes
notify:
- restart: MySQL
- hosts: wordpress
handlers:
- name: restart apache
service:
name: apache2
state: restarted
become: yes
tasks:
- name: 'Instala pacotes de dependencia do sistema operacional'
apt:
name: ['php5-fpm', 'apache2', 'libapache2-mod-php5', 'php5-gd', 'php5-mcrypt', 'python-mysqldb', 'php5-mysql']
state: latest
become: yes
- name: 'Baixa o arquivo de instalacao do Wordpress'
get_url:
url: 'https://wordpress.org/wordpress-5.0.tar.gz'
dest: '/tmp/wordpress.tar.gz'
mode: 0440
- name: 'Descompacta o wordpress'
unarchive:
src: '/tmp/wordpress.tar.gz'
dest: '/var/www/'
remote_src: yes
become: yes
- copy:
src: "{{ wp_installation_dir }}/wp-config-sample.php"
dest: "{{ wp_installation_dir }}/wp-config.php"
remote_src: yes
become: yes
- name: 'Configura o wp-config com as entradas do banco de dados'
replace:
path: "{{ wp_installation_dir }}/wp-config.php"
regexp: "{{ item.regex }}"
replace: "{{ item.value }}"
backup: yes
with_items:
- { regex: 'database_name_here', value: "{{ wp_db_name }}"}
- { regex: 'username_here', value: "{{ wp_username }}"}
- { regex: 'passaword_here', value: "{{ wp_user_password }}"}
- { regex: 'localhost', value: "{{ wp_db_ip }}"}
become: yes
- name: 'Configura Apache para servir o Wordpress'
copy:
src: 'files/000-default.conf'
dest: '/etc/apache2/sites-available/000-default.conf'
notify:
- restart apache
become: yes