eXist-db / existdb-ansible-role

Ansible role for eXist-db
GNU Lesser General Public License v2.1
11 stars 10 forks source link

[BUG] cannot access ‘/usr/local/existdb/exist/etc/system.properties’ #47

Closed gabicavalcante closed 2 years ago

gabicavalcante commented 2 years ago

Describe the bug I'm trying to use the exist-db ansible role, but I got this error message:

TASK [existdb-ansible-role : Extract system.properties file for use with Ansible fact script] ***
fatal: [default]: FAILED! => {"changed": true, "cmd": "unzip -qjd /usr/local/existdb/exist/etc /usr/local/existdb/exist/lib/exist-core*jar org/exist/system.properties; chown existdb:existdb /usr/local/existdb/exist/etc/system.properties", "delta": "0:00:00.003843", "end": "2021-11-25 17:32:05.216940", "msg": "non-zero return code", "rc": 1, "start": "2021-11-25 17:32:05.213097", "stderr": "/bin/sh: 1: unzip: not found\nchown: cannot access ‘/usr/local/existdb/exist/etc/system.properties’: No such file or directory", "stderr_lines": ["/bin/sh: 1: unzip: not found", "chown: cannot access ‘/usr/local/existdb/exist/etc/system.properties’: No such file or directory"], "stdout": "", "stdout_lines": []}

To Reproduce

The playbook:

---
- hosts: all
  gather_facts: yes
  environment:
    JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64/
    PATH: /usr/lib/jvm/java-11-openjdk-amd64/bin:{{ ansible_env.PATH }}
  roles:
    - role: gantsign.maven
      maven_version: '3.6.0'
  tasks:
    - name: Install git
      apt:
        name: git
        state: present
        update_cache: yes
    - name: Install unzip
      apt:
        name: unzip
        state: present
        update_cache: yes
    - name: Add specified repository into sources list
      ansible.builtin.apt_repository:
        repo: ppa:openjdk-r/ppa
        state: present
    - name: "Update Repository cache"
      apt:
        upgrade: dist
        update_cache: true
        cache_valid_time: 3600
        force_apt_get: true
    - name: Install OpenJDK Java
      apt:
        name: "{{ item }}"
        state: present
      with_items:
        openjdk-11-jdk
    - name: Ensure exist instance apps5test is setup
      include_role:
        name: existdb-ansible-role
      vars:
        # basic config settings, exist gets installed into $exist_home/$exist_dir
        exist_user: existdb
        exist_group: existdb
        exist_home: /usr/local/existdb
        exist_dir: existdb
        # for multiple eXist-db instances on a single host, assign an individual
        # instance name to each one. No spaces, umlauts or special chars!
        # if you're not running multiple instances the default is fine
        exist_instname: 'exist'
        exist_instuser: 'existdb'
        # exist_instdns: 'apps5test.example.com'
        exist_major_version: 5
        # exist install method: "source", "remote_archive", "local_archive", "none"
        exist_install_method: source
        # git settings (for exist_install_method == "source")
        exist_repo: https://github.com/eXist-db/exist.git
        exist_repo_version: eXist-5.3.0
        exist_repo_update: yes
        exist_repo_force: yes
        # for reference, but don't force anyone to localhost by default
        exist_http_host: '127.0.0.1'
        exist_ssl_host: '127.0.0.1'
        exist_http_port: 8080
        exist_ssl_port: 8443
        # memory settings
        exist_mem_init_heap: 4096
        exist_mem_max_heap: 4096
        # special memory/GC settings
        exist_mem_gcdebug_enable: yes
        exist_mem_strdedup_enable: yes
        exist_mem_nmt_enable: yes
        exist_mem_niocachetune_enable: yes
        exist_install_custom_xars: no
        exist_webxml_from_template: no
        exist_logconf_from_template: yes
        # enable and define loghost for logging to a central syslog server,  default
        # logging to local files only.
        exist_syslog_enable: yes
        # how many days should local log files be kept before they are deleted
        exist_log_retention_days: 30
        exist_kerneltune_enable: yes
        # whether to backup the previous exist installation
        # exist_backup_previnstall: yes
        # whether to restore the previous data directory after re-installation
        # exist_restore_prevdata: yes
        # how long to wait for exist to come up before raising an error
        # exist_startup_timeout: 300
        exist_adminpass:
          default:
            exist: MySecretPass
      tags:
        - apps5test

And the Vangrantfile where I'm testing the playbook:

Vagrant.configure("2") do |config| 
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"

  config.vm.provider "virtualbox" do |vb| 
      vb.memory = "4024" 
      vb.cpus = "1" 
  end    

  config.vm.provision "ansible" do |ansible|
      ansible.become = true
      ansible.verbose = "v"        
      # ansible.extra_vars = "ansible_extra_vars.yml"
      # ansible.vault_password_file="~/.vault_pass.txt"
      ansible.playbook = "playbook.yml"
  end
end

Context (please always complete the following information):

chakl commented 2 years ago

Note "stderr": "/bin/sh: 1: unzip: not found in the Ansible output.

You do not have the unzip program installed, so the operation fails. For Ubuntu, you probably need to run sudo apt install unzip (or similar) to install it.

Please report back whether this fixes the problem. Thanks.

chakl commented 2 years ago

The role should check that dependency. Thanks for reporting.

gabicavalcante commented 2 years ago

thanks @chakl, it worked!

I added a new task to install unzip :)

    - name: Install unzip
      apt:
        name: unzip
        state: present
        update_cache: yes

Another thing that I have noticed was this error when I try to run the playbook again (after it works):

TASK [existdb-ansible-role : Backup installed exist instance] **

fatal: [default]: FAILED! => {"changed": true, "cmd": "/usr/local/existdb/exist/contrib/exist-filebased-backup.sh -M exist existdb", "delta": "0:00:00.003873", "end": "2021-11-25 21:01:18.267224", "msg": "non-zero return code", "rc": 1, "start": "2021-11-25 21:01:18.263351", "stderr": "Illegal option -M", "stderr_lines": ["Illegal option -M"], "stdout": "Usage: /usr/local/existdb/exist/contrib/exist-filebased-backup.sh [-f] [-s] [-v] [-d bakdir] [-i instname] [-t baktype] [-u instuser]\n /usr/local/existdb/exist/contrib/exist-filebased-backup.sh [-h]\n\nOptions:\n -d place backups below this directory (default /usr/local/existdb/backup)\n -f force, skip \"proceed?\" question\n -h help (this text)\n -i backup the named exist-db instance (default exist)\n -s log to syslog\n -t backup type (rsync/tgz/fast, default rsync)\n -u exist-db instance user (default existdb)\n -v verbose", "stdout_lines": ["Usage: /usr/local/existdb/exist/contrib/exist-filebased-backup.sh [-f] [-s] [-v] [-d bakdir] [-i instname] [-t baktype] [-u instuser]", " /usr/local/existdb/exist/contrib/exist-filebased-backup.sh [-h]", "", "Options:", " -d place backups below this directory (default /usr/local/existdb/backup)", " -f force, skip \"proceed?\" question", " -h help (this text)", " -i backup the named exist-db instance (default exist)", " -s log to syslog", " -t backup type (rsync/tgz/fast, default rsync)", " -u exist-db instance user (default existdb)", " -v verbose"]}

I think this command is expecting an answer like yes to the question place backups below this directory (default /usr/local/existdb/backup)", " -f force, skip "proceed?". I can create a new issue for this error if you prefer.

gabicavalcante commented 2 years ago

For now, I set Ansible var

exist_backup_previnstall: no
exist_restore_prevdata: no

And it worked. But I'll investigate this bug because the backup it's something we need.

I got another error related to contrib/execute-xmlrpc.py.

TASK [existdb-ansible-role : Set admin password (exec set-adminpass.xql)] ** fatal: [default]: FAILED! => {"changed": true, "cmd": "contrib/execute-xmlrpc.py -u admin -p \"\" -P 8080 -T < \"/usr/local/existdb/exist/set-adminpass.xql\" && touch \"/usr/local/existdb/exist//data/.password-set\"", "delta": "0:00:00.174735", "end": "2021-11-26 15:15:17.364059", "msg": "non-zero return code", "rc": 1, "start": "2021-11-26 15:15:17.189324", "stderr": "Traceback (most recent call last):\n File \"contrib/execute-xmlrpc.py\", line 70, in \n with ServerProxy('{xmlrpcSchema}://{xmlrpcUser}:{xmlrpcPass}@{xmlrpcHost}:{xmlrpcPort}/exist/xmlrpc'.format(locals())) as proxy:\nAttributeError: exit", "stderr_lines": ["Traceback (most recent call last):", " File \"contrib/execute-xmlrpc.py\", line 70, in ", " with ServerProxy('{xmlrpcSchema}://{xmlrpcUser}:{xmlrpcPass}@{xmlrpcHost}:{xmlrpcPort}/exist/xmlrpc'.format(locals())) as proxy:", "AttributeError: exit"], "stdout": "", "stdout_lines": []}

I think ServerProxy doesn't have __exit__ method

root@vagrant-ubuntu-trusty-64:/usr/local/existdb/exist/contrib# python3 execute-xmlrpc.py -u admin -p 8080 < /usr/local/existdb/exist/set-adminpass.xql 
Namespace(B=False, L=False, Q=False, T=False, debug=False, file-name='', group='SYSTEM', host='localhost', mime='application/xml', mode='rw-r--r--', owner='admin', pass='8080', port=8080, timeout=180, user='admin')
execute-xmlrpc.py
8080
Traceback (most recent call last):
  File "execute-xmlrpc.py", line 70, in <module>
    with ServerProxy('{xmlrpcSchema}://{xmlrpcUser}:{xmlrpcPass}@{xmlrpcHost}:{xmlrpcPort}/exist/xmlrpc'.format(**locals())) as proxy:
AttributeError: __exit__

I changed to

proxy = ServerProxy('{xmlrpcSchema}://{xmlrpcUser}:{xmlrpcPass}@{xmlrpcHost}:{xmlrpcPort}/exist/xmlrpc'.format(**locals())):

And this fixed the __exit__ error.

gabicavalcante commented 2 years ago

I also found this in the execute-xmlrpc.py file:

parser.add_argument("-P", "--port", type=int, default=8080, help="URL port (default: 8443)")

It says default: 8443 but actually use 8080. And this raises a SSL error

ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:600)                                                                                                                                                                                                                       
gabicavalcante commented 2 years ago

I gonna close this issue and open a new one to report new issues.

chakl commented 2 years ago

@gabicavalcante I have committed a fix that adds "unzip" to the list of required packages in defaults/main.yml. You should not need to add a separate task just to install "unzip".

Bug confirmed and fixed. Thanks for reporting!

And thanks for moving unrelated problems to separate issue.