1
resposta

RUNNING HANDLER [restart mysql] ---- fatal: [172.17.177.42]: FAILED!

O handler não foi executado e não consigo entender. :(

RUNNING HANDLER [restart mysql] *****************************************************************************************************************************************************
fatal: [172.17.177.42]: FAILED! => {"changed": false, "msg": "value of state must be one of: started, stopped, reloaded, restarted, got: restart"}



provisioning.yml



---
- hosts: database
  handlers:
    - name: restart mysql
      service: 
        name: mysql
        state: restart
      become: yes
  tasks: 

    - name: 'Instala pacotes de dependencia do sistema operacional'
      apt:
        name: "{{ item }}"
        state: latest
      become: yes
      with_items:
        - mysql-server-5.6
        - python-mysqldb

    - name: 'Cria o banco do MySQL'
      mysql_db: 
        name: wordpress_db
        login_user: root
        state: present

    - name: 'Cria o usuário do MySQL'
      mysql_user:
        login_user: root
        name: wordpress_user
        password: 12345
        priv: 'wordpress_db.*:ALL'
        state: present
        host: "{{ item }}"
      with_items:
        - 'localhost'
        - '127.0.0.1'
        - '172.17.177.40'
    - name: 'Configura MySQL para aceitar conexões remotas'
      copy:
        src: 'files/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: "{{ item }}"
        state: latest
      become: yes
      with_items:
        - php5
        - apache2
        - libapache2-mod-php5
        - php5-gd
        - libssh2-php
        - php5-mcrypt
        - php5-mysql

    - name: 'Baixa o arquivo de instalacao do Wordpress'
      get_url:
        url: 'https://wordpress.org/wordpress-5.0.tar.gz'
        dest: '/tmp/wordpress.tar.gz'

    - name: 'Descompacta o wordpress'
      unarchive:
        src: '/tmp/wordpress.tar.gz'
        dest: /var/www/
        remote_src: yes
      become: yes

    - copy:
        src: '/var/www/wordpress/wp-config-sample.php'
        dest: '/var/www/wordpress/wp-config.php'
        remote_src: yes
      become: yes

    - name: 'Configura o wp-config com as entradas do banco de dados'     
      replace:
        path: '/var/www/wordpress/wp-config.php'
        regexp: "{{ item.regex }}"
        replace: "{{ item.value }}"
        backup: yes
      with_items:
        - { regex: 'database_name_here', value: 'wordpress_db'}
        - { regex: 'username_here', value: 'wordpress_user'}
        - { regex: 'password_here', value: '12345'}
        - { regex: 'localhost', value: '172.17.177.40'}

      become: yes

    - name: 'Configura Apache para servir o Wordpress'
      copy:
        src: 'files/000-default.conf'
        dest: '/etc/apache2/sites-available/000-default.conf'
      become: yes
      notify:
        - restart apache
1 resposta

Olá, Igor. Tudo bem?

Repare que a mensagem do erro diz:

"msg": "value of state must be one of: started, stopped, reloaded, restarted, got: restart"

Ela diz que o valor do estado que você usou é restart, mas o correto seria restarted. Se você fizer essa substituição no state do handler, deve funcionar como esperado.

Espero ter ajudado.