install_qualys-agent.playbook.yaml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---
  2. - name: "Install qualys-agent using yum/dnf/apt; activation: sudo ***CONTENTS REDACTED***"
  3. hosts: all
  4. gather_facts: True
  5. become: true
  6. vars:
  7. - install_file_path: "***CONTENTS REDACTED***Qualys/install_files/"
  8. - rpm_filename: "qualys-cloud-agent_AMD64-6.1.0-28.rpm"
  9. - deb_filename: "qualys-cloud-agent_AMD64-6.2.1.9.deb"
  10. - new_host_fqdn: "{{ ansible_fqdn }}"
  11. #################################### TEST: Customer-specific variables ####################################
  12. - cloudagent_ActivationId: "***CONTENTS REDACTED***"
  13. - cloudagent_CustomerId: "***CONTENTS REDACTED***"
  14. - cloudagent_ServerUri: "***CONTENTS REDACTED***"
  15. tasks:
  16. - name: Populate systemd service_facts
  17. service_facts:
  18. - name: "Debug: show var new_host_fqdn, ansible_facts['os_family'] & ['distribution_major_version']"
  19. debug:
  20. var: new_host_fqdn
  21. - name: "Debug: ansible_facts['os_family'] & ['distribution_major_version']"
  22. debug:
  23. msg:
  24. - os_family "{{ ansible_facts['os_family'] }}"
  25. - distribution_major_version "{{ ansible_facts['distribution_major_version'] }}"
  26. - name: "Copy rpm file to host if host is RH-like, versions 6-9"
  27. copy:
  28. src: "{{ install_file_path }}{{ rpm_filename }}"
  29. dest: /home/Ansible/{{ rpm_filename }}
  30. when:
  31. - ansible_facts['os_family'] == "RedHat"
  32. - ansible_facts['distribution_major_version'] == '6' or ansible_facts['distribution_major_version'] == '7' or ansible_facts['distribution_major_version'] == '8' or ansible_facts['distribution_major_version'] == '9'
  33. - name: "Perform installation w/ yum and rpm file if distro is RH-like versions 6-9"
  34. yum:
  35. name: /home/Ansible/{{ rpm_filename }}
  36. state: present
  37. disable_gpg_check: true
  38. when:
  39. - ansible_facts['os_family'] == "RedHat"
  40. - ansible_facts['distribution_major_version'] == '6' or ansible_facts['distribution_major_version'] == '7' or ansible_facts['distribution_major_version'] == '8' or ansible_facts['distribution_major_version'] == '9'
  41. - name: "Add firewall rules if firewalld running"
  42. firewalld:
  43. permanent: true
  44. state: enabled
  45. immediate: true
  46. rich_rule: rule family=ipv4 source address=***CONTENTS REDACTED***0 port port=10001-10005 protocol=tcp accept
  47. when: ansible_facts.services['firewalld.service'].state == 'running'
  48. ignore_errors: yes
  49. firewalld:
  50. permanent: true
  51. state: enabled
  52. immediate: true
  53. rich_rule: rule family=ipv4 source address=***CONTENTS REDACTED*** port port=10001-10005 protocol=tcp accept
  54. when: ansible_facts.services['firewalld.service'].state == 'running'
  55. ignore_errors: yes
  56. firewalld:
  57. permanent: true
  58. state: enabled
  59. immediate: true
  60. rich_rule: rule family=ipv4 source address=***CONTENTS REDACTED*** port port=10001-10005 protocol=tcp accept
  61. when: ansible_facts.services['firewalld.service'].state == 'running'
  62. ignore_errors: yes
  63. firewalld:
  64. permanent: true
  65. state: enabled
  66. immediate: true
  67. rich_fule: rule family=ipv4 source address=***CONTENTS REDACTED*** port port=10001-10005 protocol=tcp accept
  68. when: ansible_facts.services['firewalld.service'].state == 'running'
  69. ignore_errors: yes
  70. firewalld:
  71. permanent: true
  72. state: enabled
  73. immediate: true
  74. rich_rule: rule family=ipv4 source address=***CONTENTS REDACTED*** port port=10001-10005 protocol=tcp accept
  75. when: ansible_facts.services['firewalld.service'].state == 'running'
  76. # For Deb-like:
  77. - name: "Copy deb file to host if host is Debian 7 through 12, Bookworm"
  78. copy:
  79. src: "{{ install_file_path }}{{ deb_filename }}"
  80. dest: /home/Ansible/{{ deb_filename }}
  81. when:
  82. - ansible_facts['os_family'] == 'Debian'
  83. - name: "Install deb file on host if distro is Debian-like"
  84. apt:
  85. deb: /home/Ansible/{{ deb_filename }}
  86. state: present
  87. when:
  88. - ansible_facts['os_family'] == 'Debian'
  89. ######################################### Init agent w/ ActivationID, CustomerID and ServerUri #########################################
  90. - name: "Make one-liner executable"
  91. file:
  92. path: ***CONTENTS REDACTED***/qualys-cloud-agent.sh
  93. mode: "0750"
  94. - name: "Run one-liner to provide cloud-agent ActivationID, CustomerID and ServerUri"
  95. command: /usr/local/qualys/cloud-agent/bin/qualys-cloud-agent.sh ActivationId="{{ cloudagent_ActivationId }}" CustomerId="{{ cloudagent_CustomerId }}" ServerUri="{{ cloudagent_ServerUri }}"
  96. - name: "Restart the cloud-agent service"
  97. service:
  98. name: qualys-cloud-agent
  99. state: restarted
  100. enabled: yes