freeipa / ansible-freeipa

Ansible roles and modules for FreeIPA
GNU General Public License v3.0
505 stars 231 forks source link

TASK [ipareplica : Install - Setup DNS] - AttributeError: 'AnsibleModuleLog' object has no attribute 'isatty' #251

Closed pavel-z1 closed 2 years ago

pavel-z1 commented 4 years ago

Hi

I try to install FreeIPA on CentOS 8. All installation steps (Setup DS, Setup CA) works, except setup DNS role.

During execution TASK [ipareplica : Install - Setup DNS] I receive error:

AttributeError: 'AnsibleModuleLog' object has no attribute 'isatty'

Full Traceback:

The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 102, in <module>
  File "<stdin>", line 94, in _ansiballz_main
  File "<stdin>", line 40, in invoke_module
  File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload_h7dzqavh/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload.zip/ansible_collections/freeipa/ansible_freeipa/plugins/modules/ipareplica_setup_dns.py", line 191, in <module>
  File "/tmp/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload_h7dzqavh/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload.zip/ansible_collections/freeipa/ansible_freeipa/plugins/modules/ipareplica_setup_dns.py", line 180, in main
  File "/usr/lib/python3.6/site-packages/ipaserver/install/dns.py", line 381, in install
    bind.check_global_configuration()
  File "/usr/lib/python3.6/site-packages/ipaserver/install/bindinstance.py", line 1190, in check_global_configuration
    reverse=False)
  File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 1086, in output_for_cli
    textui.print_entry(result, order, labels, flags, print_all)
  File "/usr/lib/python3.6/site-packages/ipalib/cli.py", line 423, in print_entry
    label, value, format, indent, one_value_per_line
  File "/usr/lib/python3.6/site-packages/ipalib/cli.py", line 334, in print_attribute
    line_len = self.get_tty_width()
  File "/usr/lib/python3.6/site-packages/ipalib/cli.py", line 110, in get_tty_width
    if sys.stdout.isatty():
AttributeError: 'AnsibleModuleLog' object has no attribute 'isatty'
fatal: [10.60.64.32]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 102, in <module>\n  File \"<stdin>\", line 94, in _ansiballz_main\n  File \"<stdin>\", line 40, in invoke_module\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload_h7dzqavh/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload.zip/ansible_collections/freeipa/ansible_freeipa/plugins/modules/ipareplica_setup_dns.py\", line 191, in <module>\n  File \"/tmp/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload_h7dzqavh/ansible_freeipa.ansible_freeipa.ipareplica_setup_dns_payload.zip/ansible_collections/freeipa/ansible_freeipa/plugins/modules/ipareplica_setup_dns.py\", line 180, in main\n  File \"/usr/lib/python3.6/site-packages/ipaserver/install/dns.py\", line 381, in install\n    bind.check_global_configuration()\n  File \"/usr/lib/python3.6/site-packages/ipaserver/install/bindinstance.py\", line 1190, in check_global_configuration\n    reverse=False)\n  File \"/usr/lib/python3.6/site-packages/ipalib/frontend.py\", line 1086, in output_for_cli\n    textui.print_entry(result, order, labels, flags, print_all)\n  File \"/usr/lib/python3.6/site-packages/ipalib/cli.py\", line 423, in print_entry\n    label, value, format, indent, one_value_per_line\n  File \"/usr/lib/python3.6/site-packages/ipalib/cli.py\", line 334, in print_attribute\n    line_len = self.get_tty_width()\n  File \"/usr/lib/python3.6/site-packages/ipalib/cli.py\", line 110, in get_tty_width\n    if sys.stdout.isatty():\nAttributeError: 'AnsibleModuleLog' object has no attribute 'isatty'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

I saw closed issue https://github.com/freeipa/ansible-freeipa/issues/117 but no solution is provided. Can you please help to solve issue?

rjeffman commented 4 years ago

The error is occuring inside ipalib, part of FreeIPA, it might be an issue there or on ansible-freeipa.

Can you provide CentOS and package versions? Can you provide details on the configuration you are using so that it can be reproduced?

pavel-z1 commented 4 years ago

Hi @rjeffman

I am use CentOS Linux release 8.1.1911 (Core) with kernel 4.18.0-147.8.1.el8_1.x86_64. This is latest public CentOS 8.

Steps to reproduce issue:

  1. Install FreeIPA Master server with any default parameters and enabled DNS role on master server.
  2. Configure vars to enable Replica DNS role, variables should be applied to the new replica server:
    ipareplica_setup_dns: yes
    ipareplica_forwarders:
    - 8.8.8.8
    - 1.1.1.1
  3. Install Replica server with enabled DNS via ansible playbook. It is important to enable ipareplica_setup_dns befor start setup replica server. Ipa replica role won't setup DNS role if IPA replica was installed previously on server.
MannerMan commented 4 years ago

Having the same problem trying to use these ansible roles for a FreeIPA deployment on CentOS 8!

MannerMan commented 4 years ago

We did a temporary try-catch patch for /usr/lib/python3.6/site-packages/ipalib/cli.py to get around this error for now;

        try:
            if sys.stdout.isatty():
                try:
                    winsize = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ,
                                        struct.pack('HHHH', 0, 0, 0, 0))
                    return struct.unpack('HHHH', winsize)[1]
                except IOError:
                    pass
        except AttributeError:
            pass
        return None
iomnium commented 4 years ago

I had exactly the same issue on an updated CentOS 8. I fixed that by adding the missing isatty method to theAnsibleModuleLog class.

diff --git a/roles/ipareplica/module_utils/ansible_ipa_replica.py b/roles/ipareplica/module_utils/ansible_ipa_replica.py
index b0f0d03..f6681d5 100644
--- a/roles/ipareplica/module_utils/ansible_ipa_replica.py
+++ b/roles/ipareplica/module_utils/ansible_ipa_replica.py
@@ -191,6 +191,9 @@ class AnsibleModuleLog():
     def info(self, msg):
         self.module.debug(msg)

+    def isatty(self):
+        return False
+
     def write(self, msg):
         self.module.debug(msg)
         # self.module.warn(msg)
Drugantibus commented 2 years ago

Just run into this issue 2 years later. Is there any reason keeping those 3 lines from being added upstream?

rjeffman commented 2 years ago

I wonder why this does happen, as CentOS is used a lot on testing and I was never able to reproduce this. My guess is that this is shadowing another issue.

@Drugantibus can you provide the settings you are using to deploy the replica?

Drugantibus commented 2 years ago

@rjeffman This is actually on Fedora 34 ("Cloud Edition", on EC2). Here are the vars used:

ipaserver_domain: ***
ipaserver_realm: ***
ipaserver_setup_dns: true
ipaserver_forwarders: 10.0.0.2
ipaserver_reverse_zones: 0.10.in-addr.arpa
ipaserver_allow_zone_overlap: true
ipaserver_no_dnssec_validation: true

ipareplica_server: ipa01.***
ipareplica_setup_dns: true
ipareplica_setup_ca: true
ipareplica_forwarders: 10.0.0.2
ipareplica_no_dnssec_validation: true

ipaclient_mkhomedir: true
ipaclient_all_ip_addresses: true
ipaclient_ssh_trust_dns: true
ipasssd_enable_dns_updates: true
rjeffman commented 2 years ago

@Drugantibus can you deploy the replica using the command line, in the same environment?

infra-monkey commented 2 years ago

Just ran into this issue on centos stream 9 with ansible_freeipa 1.8.1 With the workaround from iiomnium it passes.

@rjeffman I can do some tests if you need someone.