2016-04-15 23 views
18

Ho un ansible 2.1.0 sul mio server, dove eseguo la distribuzione tramite vagabondo e anche su PC. Il ruolo "distribuire" hanno:Ansible 2.1.0 utilizzando diventa/diventa_user non riesce a impostare le autorizzazioni sul file temporaneo

- name: upload code 
    become: true 
    become_user: www-data 
    git: [email protected]:****.git 
    dest=/var/www/main 
    key_file=/var/www/.ssh/id_rsa 
    accept_hostkey=true 
    update=yes 
    force=yes 
register: fresh_code 
notify: restart php-fpm 
tags: fresh_code 

in questo caso con ansible 2.1.0 ottengo un errore:

fatal: [default]: FAILED! => {"failed": true, "msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user. For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"} 

Si è ansible 2.0.1.0 che uso sul mio PC, è tutto normalmente - cartella/var/www/have cartella principale con proprietario e gruppo www-data

Se utilizzo solo diventato_user: www-data e se uso diventato_method: sudo con diventato_user: www-data - ho ricevuto lo stesso errore

Che cosa è necessario fare per risolvere questo problema?

risposta

14

Il problema è che www-data non può accedere agli stessi file dell'utente predefinito non root ansable creato che si utilizza per connettersi alla macchina. Anche il messaggio di errore indica chiaramente ansible's documentation che descrive quali opzioni è necessario risolvere questo problema durante l'aggiornamento da 2.0 ansible o inferiore.

Essi suggeriscono tre modi per risolvere correttamente il problema:

  • Use pipelining. When pipelining is enabled, Ansible doesn’t save the module to a temporary file on the client. Instead it pipes the module to the remote python interpreter’s stdin. Pipelining does not work for non-python modules.
  • Install filesystem acl support on the managed host. If the temporary directory on the remote host is mounted with filesystem acls enabled and the setfacl tool is in the remote PATH then Ansible will use filesystem acls to share the module file with the second unprivileged instead of having to make the file readable by everyone.
  • Don’t perform an action on the remote machine by becoming an unprivileged user. Temporary files are protected by UNIX file permissions when you become root or do not use become. In Ansible 2.1 and above, UNIX file permissions are also secure if you make the connection to the managed machine as root and then use become to an unprivileged account.

Oppure, se non si può fare nessuna di queste correzioni, allora è possibile forzare ansible per l'esecuzione in un po 'modo più insicuro (che sembrava essere il predefinito in ansible 2 e al di sotto), che dovrebbe anche risolvere il problema, ma non sarebbe risolvere il rischio per la sicurezza sottostante:

If you can’t make any of the changes above to resolve the problem and you decide that the machine you’re running on is secure enough for the modules you want to run there to be world readable you can turn on allow_world_readable_tmpfiles in the ansible.cfg file. Setting allow_world_readable_tmpfiles will change this from an error into a warning and allow the task to run as it did prior to 2.1.

+3

Grazie per la riproduzione. Per me aiuto seconda risposta. Ho installato acl-tools e questo risolve il problema. Nel libro dei giochi io uso 'become: true become_user: www-data' e tutto va bene – DeamonMV

+2

Installare il modulo' acl' sui server Debian (Opzione 2) era di gran lunga l'opzione più semplice per me, e questo funziona anche se si ha file temporanei sul server "abilitato per il debug. Ho rinunciato a far funzionare il pipelining Ansible (client OS X 10.11, server Debian 7, provato varie modifiche al file di configurazione ma niente ha funzionato). Ho anche scoperto che l'uso dell'opzione "Connetti come root" si verificava in un bug non correlato in cui la maggior parte del playbook veniva saltata silenziosamente. – RichVel

+0

Se si ottengono questi sintomi difficili da utilizzare con Google usando la tecnica "connect as root" con '--ask-become-password' (opzione 3), la causa principale è questo problema - basta installare il modulo' acl' su correggili: "Playbook chiede la password sudo e la usa su sudo (si ottiene un errore di password se digitata male) ma poi esce senza errori dopo l'attività implicita [setup] (che sembra avere successo)". Sembra un bug Ansible 2.1.0. – RichVel

35

su Debian/Ubuntu è possibile risolvere questo installando prima il pacchetto acl sulla macchina remota, come con questo compito impossibile:

- name: install setfacl support 
    become: yes 
    apt: pkg=acl 

Stessa cosa con RedHat/CentOS - installare il pacchetto acl sulla macchina remota:

- name: install setfacl support 
    become: yes 
    yum: name=acl 
+0

Ciò richiede modifiche a 'fstab' o un riavvio? – meshy

+0

Non ho richiesto il riavvio nel mio caso. –

Problemi correlati