install_bacula_client.yaml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ---
  2. - name: "Install Bacula Client"
  3. hosts: all
  4. gather_facts: True
  5. become: true
  6. tasks:
  7. - include_tasks: ../include/determine_which_firewall.yaml
  8. - name: Set variable for the current version of bacula-client
  9. set_fact:
  10. BACULAVERSION: "15.0.2"
  11. ################################################ create/copy repo file to hosts and import PGP key (if necessary)
  12. - name: Copy signing key to RH-like hosts using the old manual command
  13. command:
  14. # cmd: rpmkeys --import https://bacula.space.swri.edu/repo/{{ BACULAVERSION }}/Bacula-15.0.2-public.key
  15. cmd: rpmkeys --import https://bacula.space.swri.edu/repo/{{ BACULAVERSION }}/repomd.xml.key
  16. when: (ansible_facts['distribution_file_variety'] == 'RedHat')
  17. - name: Copy/overwrite, bacula-community.repo to RHEL-like hosts
  18. copy:
  19. force: true
  20. src: include/bacula-community.repo
  21. dest: /etc/yum.repos.d/bacula-community.repo
  22. owner: root
  23. group: root
  24. mode: '0640'
  25. when: (ansible_facts['distribution_file_variety'] == 'RedHat')
  26. - name: Copy signing key to Deb-like hosts
  27. copy:
  28. src: include/Bacula-4096-Distribution-Verification-key.asc
  29. dest: /etc/apt/trusted.gpg.d/bacula-community-localmirror.asc
  30. when: (ansible_facts['distribution_file_variety'] == 'Debian')
  31. - name: Create /etc/apt/sources.list.d/bacula-community.list on Debian-like hosts
  32. copy:
  33. dest: /etc/apt/sources.list.d/bacula-community.list
  34. owner: root
  35. group: root
  36. mode: '0640'
  37. content: |
  38. deb https://bacula.space.swri.edu/repo/{{ BACULAVERSION }}/debs {{ ansible_lsb.codename }} main
  39. when: (ansible_facts['distribution_file_variety'] == 'Debian')
  40. ############################################### remove old verions of bacula-client
  41. - name: Gather the package facts
  42. package_facts:
  43. manager: auto
  44. - name: Print the package facts
  45. ansible.builtin.debug:
  46. var: ansible_facts.packages
  47. - name: Debug- output ansible_facts.packages bacula-client
  48. ansible.builtin.debug:
  49. # msg: "{{ ansible_facts.packages['bacula-client']| map(attribute='version')|list|first }} is installed"
  50. msg:
  51. # - "{{ ansible_facts.packages['bacula-client']| map(attribute='version') | first }}"
  52. - "{{ ansible_facts.packages['bacula-client']| map(attribute='version') | first }}"
  53. ignore_errors: yes
  54. when: (ansible_facts.packages['bacula-client'] is defined)
  55. - name: Remove bacula-client, etc. if version isn't 13-15
  56. ansible.builtin.package:
  57. name:
  58. - bacula-client
  59. - bacula-common
  60. - bacula-console
  61. - bacula-fd
  62. state: absent
  63. when:
  64. - (ansible_facts.packages['bacula-client'] is defined)
  65. - "'15' not in ansible_facts.packages['bacula-client']| map(attribute='version') | first"
  66. - "'14' not in ansible_facts.packages['bacula-client']| map(attribute='version') | first"
  67. - "'13' not in ansible_facts.packages['bacula-client']| map(attribute='version') | first"
  68. ############################################### install using pkg mgr
  69. - name: 'Install Bacula Client & Bacula console from newly created repo for RHEL-like distros'
  70. yum:
  71. name:
  72. - bacula-client
  73. state: latest
  74. update_cache: true
  75. when: (ansible_facts['distribution_file_variety'] == 'RedHat')
  76. - name: 'Install Bacula Client & bacula-console from newly created repo for Deb-like repos'
  77. apt:
  78. name:
  79. - bacula-client
  80. state: present
  81. when: (ansible_facts['distribution_file_variety'] == 'Debian')
  82. ################################################ Copy config files #################################################
  83. # Copy Bacula Client config file to host
  84. - name: perform copy of bacula-fd.conf
  85. copy:
  86. src: ~/playbooks/bacula/include/bacula-fd.conf
  87. dest: /etc/bacula/bacula-fd.conf
  88. owner: root
  89. group: root
  90. mode: '0640'
  91. ################################################ Add Fireall Rules #################################################
  92. - name: 'Allow bacula-client service using firewalld'
  93. firewalld:
  94. service: bacula-client
  95. permanent: True
  96. state: enabled
  97. immediate: True
  98. when: which_firewall == 'firewalld'
  99. ignore_errors: yes
  100. - name: 'Allow bacula-client service using iptables'
  101. iptables:
  102. chain: INPUT
  103. prorocol: TCP
  104. destination_port: "9102"
  105. when: which_firewall == 'iptables'
  106. ignore_errors: yes
  107. - name: 'Allow bacula-client service using ufw'
  108. ufw:
  109. rule: allow
  110. port: '9102'
  111. proro: tcp
  112. when: which_firewall == 'ufw'
  113. ignore_errors: yes
  114. ################################################ Service/Systemd Section #################################################
  115. # Enable bacula-fd on systemd-enabled systems:
  116. - name: enable bacula-fd service
  117. systemd:
  118. name: bacula-fd
  119. enabled: True
  120. masked: no
  121. state: restarted
  122. ignore_errors: False
  123. #when: ansible_facts.services['source'].source == systemd
  124. when: ansible_facts.service_mgr == "systemd"