Setup production : bench.exceptions.CommandFailedError

when i trid to sudo bench setup production erpnext
i got this error

erpnext@vmi1053547:~/frappe-bench$ sudo bench setup production erpnext
[sudo] password for erpnext: 
Setting Up prerequisites...
$ bench setup role fail2ban
ansible-playbook [core 2.13.6]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]
  jinja version = 3.0.3
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[DEPRECATION WARNING]: "include" is deprecated, use include_tasks/import_tasks instead. This feature will be removed in version 2.16. Deprecation warnings can be disabled 
by setting deprecation_warnings=False in ansible.cfg.
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/centos.yml
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml
statically imported: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
Loading collection community.general from /usr/local/lib/python3.10/dist-packages/ansible_collections/community/general
redirecting (type: modules) community.general.homebrew to community.general.packaging.os.homebrew
redirecting (type: modules) ansible.builtin.selinux to ansible.posix.selinux
Loading collection ansible.posix from /usr/local/lib/python3.10/dist-packages/ansible_collections/ansible/posix
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.10/dist-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: site.yml *********************************************************************************************************************************************************
Positional arguments: site.yml
verbosity: 4
connection: local
timeout: 10
become_method: sudo
tags: ('fail2ban',)
inventory: ('/etc/ansible/hosts',)
extra_vars: ('{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}',)
forks: 5
2 plays in site.yml

PLAY [localhost] ***********************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/site.yml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771 `" && echo ansible-tmp-1668538964.6242716-22653-1564325248771="` echo /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771 `" ) && sleep 0'
Using module file /usr/local/lib/python3.10/dist-packages/ansible/modules/setup.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-2264816r0sf66/tmpve9bbo_2 TO /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771/ /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1668538964.6242716-22653-1564325248771/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 
META: 

TASK [fail2ban : Install fail2ban] *****************************************************************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/fail2ban/tasks/main.yml:2
skipping: [localhost] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}

TASK [fail2ban : Install fail2ban] *****************************************************************************************************************************************
task path: /usr/local/lib/python3.10/dist-packages/bench/playbooks/roles/fail2ban/tasks/main.yml:6
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687 `" && echo ansible-tmp-1668538966.2087853-22708-172520240124687="` echo /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687 `" ) && sleep 0'
Using module file /usr/local/lib/python3.10/dist-packages/ansible/modules/apt.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-2264816r0sf66/tmpd5oj644k TO /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687/AnsiballZ_apt.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687/ /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687/AnsiballZ_apt.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687/AnsiballZ_apt.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1668538966.2087853-22708-172520240124687/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "cache_update_time": 1666466629,
    "cache_updated": false,
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_change_held_packages": false,
            "allow_downgrade": false,
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "clean": false,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "fail_on_autoremove": false,
            "force": false,
            "force_apt_get": false,
            "install_recommends": null,
            "lock_timeout": 60,
            "name": "fail2ban",
            "only_upgrade": false,
            "package": [
                "fail2ban"
            ],
            "policy_rc_d": null,
            "purge": false,
            "state": "present",
            "update_cache": null,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"       install 'fail2ban=0.11.2-6'' failed: E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).\n",
    "rc": 100,
    "stderr": "E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).\n",
    "stderr_lines": [
        "E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)."
    ],
    "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nYou might want to run 'apt --fix-broken install' to correct these.\nThe following packages have unmet dependencies:\n wkhtmltox : Depends: xfonts-75dpi but it is not going to be installed\n",
    "stdout_lines": [
        "Reading package lists...",
        "Building dependency tree...",
        "Reading state information...",
        "You might want to run 'apt --fix-broken install' to correct these.",
        "The following packages have unmet dependencies:",
        " wkhtmltox : Depends: xfonts-75dpi but it is not going to be installed"
    ]
}

PLAY RECAP *****************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0   

ERROR: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}', '-t', 'fail2ban']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/bench/cli.py", line 127, in cli
    bench_command()
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bench/commands/setup.py", line 368, in setup_roles
    run_playbook("site.yml", extra_vars=extra_vars, tag=role)
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/__init__.py", line 322, in run_playbook
    subprocess.check_call(args, cwd=os.path.join(bench.__path__[0], "playbooks"))
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}', '-t', 'fail2ban']' returned non-zero exit status 2.
ERROR: 
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/bench/cli.py", line 127, in cli
    bench_command()
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bench/commands/setup.py", line 108, in setup_production
    setup_production(user=user, yes=yes)
  File "/usr/local/lib/python3.10/dist-packages/bench/config/production_setup.py", line 37, in setup_production
    setup_production_prerequisites()
  File "/usr/local/lib/python3.10/dist-packages/bench/config/production_setup.py", line 28, in setup_production_prerequisites
    exec_cmd("bench setup role fail2ban")
  File "/usr/local/lib/python3.10/dist-packages/bench/utils/__init__.py", line 155, in exec_cmd
    raise CommandFailedError
bench.exceptions.CommandFailedError

solved :
sudo apt --fix-broken install

1 Like

I have the same error, I tried the sudo apt --fix-broke install but it did not work

See below for the error I am getting:

pi@simplepi:~/frappe-bench $ sudo bench setup production pi
Setting Up prerequisites...
$ bench setup role fail2ban
ansible-playbook [core 2.14.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.10.0 (default, Dec 13 2022, 00:16:33) [GCC 10.2.1 20210110] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[DEPRECATION WARNING]: "include" is deprecated, use include_tasks/import_tasks instead. See https://docs.ansible.com/ansible-core/2.14/user_guide/playbooks_reuse_includes.html for details. This 
feature will be removed in version 2.16. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
statically imported: /usr/local/lib/python3.10/site-packages/bench/playbooks/roles/mariadb/tasks/centos.yml
statically imported: /usr/local/lib/python3.10/site-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml
statically imported: /usr/local/lib/python3.10/site-packages/bench/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml
redirecting (type: modules) ansible.builtin.homebrew to community.general.homebrew
Loading collection community.general from /usr/local/lib/python3.10/site-packages/ansible_collections/community/general
redirecting (type: modules) ansible.builtin.selinux to ansible.posix.selinux
Loading collection ansible.posix from /usr/local/lib/python3.10/site-packages/ansible_collections/ansible/posix
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.10/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: site.yml **********************************************************************************************************************************************************************************
Positional arguments: site.yml
verbosity: 4
connection: local
timeout: 10
become_method: sudo
tags: ('fail2ban',)
inventory: ('/etc/ansible/hosts',)
extra_vars: ('{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}',)
forks: 5
2 plays in site.yml

PLAY [localhost] ************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************
task path: /usr/local/lib/python3.10/site-packages/bench/playbooks/site.yml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819 `" && echo ansible-tmp-1670958377.3884277-1481-112388929298819="` echo /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819 `" ) && sleep 0'
Using module file /usr/local/lib/python3.10/site-packages/ansible/modules/setup.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-1476s1756jzx/tmph6p74myt TO /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819/ /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1670958377.3884277-1481-112388929298819/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "cmd": "/usr/bin/lsb_release -a",
            "exception": "  File \"/tmp/ansible_ansible.legacy.setup_payload_1p02qukx/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py\", line 2022, in run_command\n    cmd = subprocess.Popen(args, **kwargs)\n  File \"/usr/local/lib/python3.10/subprocess.py\", line 966, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/usr/local/lib/python3.10/subprocess.py\", line 1842, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\n",
            "failed": true,
            "invocation": {
                "module_args": {
                    "fact_path": "/etc/ansible/facts.d",
                    "filter": [],
                    "gather_subset": [
                        "all"
                    ],
                    "gather_timeout": 10
                }
            },
            "msg": "[Errno 2] No such file or directory: b'/usr/bin/lsb_release'",
            "rc": 2,
            "stderr": "",
            "stderr_lines": [],
            "stdout": "",
            "stdout_lines": []
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}

PLAY RECAP ******************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

ERROR: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}', '-t', 'fail2ban']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/site-packages/bench/cli.py", line 127, in cli
    bench_command()
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/bench/commands/setup.py", line 368, in setup_roles
    run_playbook("site.yml", extra_vars=extra_vars, tag=role)
  File "/usr/local/lib/python3.10/site-packages/bench/utils/__init__.py", line 325, in run_playbook
    subprocess.check_call(args, cwd=os.path.join(bench.__path__[0], "playbooks"))
  File "/usr/local/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ansible-playbook', '-c', 'local', 'site.yml', '-vvvv', '-e', '{"production": true, "admin_emails": "", "mysql_root_password": null, "container": false}', '-t', 'fail2ban']' returned non-zero exit status 2.
ERROR: 
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/site-packages/bench/cli.py", line 127, in cli
    bench_command()
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/bench/commands/setup.py", line 108, in setup_production
    setup_production(user=user, yes=yes)
  File "/usr/local/lib/python3.10/site-packages/bench/config/production_setup.py", line 37, in setup_production
    setup_production_prerequisites()
  File "/usr/local/lib/python3.10/site-packages/bench/config/production_setup.py", line 28, in setup_production_prerequisites
    exec_cmd("bench setup role fail2ban")
  File "/usr/local/lib/python3.10/site-packages/bench/utils/__init__.py", line 158, in exec_cmd
    raise CommandFailedError
bench.exceptions.CommandFailedError

Thanks Abdullah