Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for python2.6 compatibility #1

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions plugins/modules/link_agent_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@
"""


import subprocess

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native


def link_nessus_agent(module):
Expand All @@ -114,21 +113,13 @@ def link_nessus_agent(module):
become = module.params["become"]

sudo_prefix = "sudo " if become else ""
command = (
f"{sudo_prefix}/opt/nessus_agent/sbin/nessuscli agent link "
f'--name="{name}" --key={linking_key} --groups="{groups}" '
f'--network="{network}" --host="{host}" --port={port}'
command = "{} /opt/nessus_agent/sbin/nessuscli agent link --name='{}' --key={} --groups='{}' --network='{}' --host='{}' --port={}".format(
sudo_prefix, name, linking_key, groups, network, host, port
)

try:
result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, timeout=10)
output = result.decode("utf-8")
return True, output, 0, True
except subprocess.TimeoutExpired:
module.fail_json(msg="Error: Command timed out. Tenable might not be installed.", rc=124)
except subprocess.CalledProcessError as e:
error_message = e.output.decode()
module.fail_json(msg=f"Failed to link Nessus Agent: {error_message}", rc=e.returncode)
rc, stdout, stderr = module.run_command(command, use_unsafe_shell=True)
if rc != 0:
module.fail_json(changed=False, stdout=to_native(stdout), stderr=to_native(stderr), rc=rc)
return True, stdout, stderr, rc


def main():
Expand All @@ -145,9 +136,9 @@ def main():
supports_check_mode=False,
)

is_linked, output, rc, changed = link_nessus_agent(module)
is_linked, stdout, stderr, rc = link_nessus_agent(module)
if is_linked:
module.exit_json(changed=changed, msg=output, rc=rc)
module.exit_json(changed=True, stdout=stdout, stderr=stderr, rc=rc)


if __name__ == "__main__":
Expand Down
23 changes: 9 additions & 14 deletions plugins/modules/unlink_agent_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,18 @@
"""


import subprocess

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native


def unlink_nessus_agent(module):
command = "/opt/nessus_agent/sbin/nessuscli agent unlink"

try:
subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
return True, "Nessus Agent unlinked successfully"
except subprocess.CalledProcessError as e:
output = e.output.decode()
if "No host information found" in output:
return True, "No Agent is running on the server, no need to unlink"
else:
module.fail_json(msg=f"Failed to unlink Nessus Agent: {output}")
rc, stdout, stderr = module.run_command(command, use_unsafe_shell=True)
stdout = to_native(stdout)
stderr = to_native(stderr)
if rc != 0:
module.fail_json(changed=False, stdout=stdout, stderr=stderr, rc=rc)
return True, stdout, stderr, rc


def main():
Expand All @@ -60,9 +55,9 @@ def main():
supports_check_mode=False,
)

is_unlinked, message = unlink_nessus_agent(module)
is_unlinked, stdout, stderr, rc = unlink_nessus_agent(module)
if is_unlinked:
module.exit_json(changed=True, msg=message)
module.exit_json(changed=True, stdout=stdout, stderr=stderr, rc=rc)


if __name__ == "__main__":
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ src_paths = [
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "ANSIBLE_CORE", "LOCALFOLDER"]
known_third_party = ["botocore", "boto3"]
known_ansible_core = ["ansible"]
known_ansible_amazon_aws = ["ansible_collections.amazon.aws"]
known_ansible_community_aws = ["ansible_collections.community.aws"]

[tool.flynt]
transform-joins = true
exclude = [
"ec2_metadata_facts",
]
Loading