Thank you for reading this post, don't forget to subscribe!
cat /etc/ansible/playbooks/roles_play/activemq.yml
1 2 3 4 5 6 7 8 9 10 11 |
--- - hosts: 192.168.1.170 become: true ignore_errors: yes become_method: sudo gather_facts: yes vars: directory_for_activemq: /var roles: - activemq |
cat /etc/ansible/roles/activemq/handlers/main.yml
1 2 3 4 |
--- - name: restart activemq service: name=activemq state=restarted enabled=yes |
cat /etc/ansible/roles/activemq/templates/activemq.service
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description=activemq message queue After=network.target [Service] PIDFile={{ directory_for_activemq }}/activemq/data/activemq.pid ExecStart={{ directory_for_activemq }}/activemq/bin/activemq start ExecStop={{ directory_for_activemq }}/activemq/bin/activemq stop User=root Group=root [Install] WantedBy=multi-user.target |
cat /etc/ansible/roles/activemq/tasks/addusers.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
- name: Ensure group activemq exists group: name: "{{ item }}" state: present with_items: - activemq - name: add user activemq user: name: "{{ item }}" group: activemq shell: /sbin/nologin append: yes with_items: - activemq |
cat /etc/ansible/roles/activemq/tasks/systemct_conf.yaml
1 2 3 4 5 6 7 8 |
- name: Copy activemq service config to remote host for centos 7 template: src=/etc/ansible/roles/activemq/templates/activemq.service dest=/etc/systemd/system/activemq.service notify: - restart activemq when: - ansible_distribution_major_version == "7" - ansible_distribution == "CentOS" |
cat /etc/ansible/roles/activemq/tasks/main.yml
1 2 3 4 5 6 7 8 |
--- - import_tasks: addusers.yml tags: adduser - import_tasks: defaultpackages.yml tags: default - import_tasks: systemct_conf.yaml tags: activemq_systemctl_conf |
cat /etc/ansible/roles/activemq/tasks/defaultpackages.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
- name: "Check java installed" package_facts: manager: "auto" - name: "if java installed all OK" debug: msg: "Packpage FOUND and all ok" when: "'java' in ansible_facts.packages or 'openjdk' in ansible_facts.packages or 'java-1.8.0-openjdk' in ansible_facts.packages or 'jdk1.8' in ansible_facts.packages" - name: "java NOT installed" debug: msg: "Packpage NOT installed" when: - "'java' not in ansible_facts.packages" - "'openjdk' not in ansible_facts.packages" - "'java-1.8.0-openjdk' not in ansible_facts.packages" - "'jdk1.8' not in ansible_facts.packages" - name: install wget yum: name: wget state: present when: ansible_os_family == 'RedHat' - name: download Oracle JDK shell: "cd {{ directory_for_activemq }} && wget --header 'Cookie: oraclelicense=accept-securebackup-cookie' https://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.rpm" args: creates: "{{ directory_for_activemq }}/jdk-8u281-linux-x64.rpm" when: ansible_os_family == 'RedHat' - name: Install JAVA RPM jdk-8u281-linux-x64.rpm. yum: name: "{{ directory_for_activemq }}/jdk-8u281-linux-x64.rpm" state: present when: "'java' not in ansible_facts.packages or 'openjdk' not in ansible_facts.packages or 'java-1.8.0-openjdk' not in ansible_facts.packages or 'jdk1.8' not in ansible_facts.packages" - name: "Check java installed second time" package_facts: manager: "auto" - name: Add JAVA_HOME to /etc/environment shell: | echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a >> /etc/environment cat /etc/environment | sort | uniq > /etc/environment2 cat /etc/environment2 > /etc/environment rm -rf /etc/environment2 when: "'java' in ansible_facts.packages or 'openjdk' in ansible_facts.packages or 'java-1.8.0-openjdk' in ansible_facts.packages or 'jdk1.8' in ansible_facts.packages" - name: check dir for activemq stat: path: "{{ directory_for_activemq }}/activemq" register: register_name - name: DOWNLOAD apache-activemq-5.14.3-bin.tar.gz get_url: url: https://archive.apache.org/dist/activemq/5.14.3/apache-activemq-5.14.3-bin.tar.gz dest: "{{ directory_for_activemq }}" when: not register_name.stat.exists - name: Unarchive a file that is already on the remote machine unarchive: src: "{{ directory_for_activemq }}/apache-activemq-5.14.3-bin.tar.gz" dest: "{{ directory_for_activemq }}" remote_src: yes when: not register_name.stat.exists - name: Move dir and remove archive shell: mv {{ directory_for_activemq }}/apache-activemq-5.14.3 {{ directory_for_activemq }}/activemq && rm -rf {{ directory_for_activemq }}/apache-activemq-5.14.3-bin.tar.gz when: not register_name.stat.exists - name: Change permissions on activemq folder file: dest: "{{ directory_for_activemq }}/activemq" owner: activemq group: activemq mode: u=rwX,g=rX,o=rX recurse: yes |
самая ебанутая часть происходит в момент выкачивания oracle openjdk
wget --header 'Cookie: oraclelicense=accept-securebackup-cookie' https://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.rpm
как мы получаем эту ссылку:
идём по ссылке:
https://www.oracle.com/in/java/technologies/javase/javase-jdk8-downloads.html
ну или той версии которая нужна. (необходимо зарегаться, по другому там никак)
получаем ссылку:
https://download.oracle.com/otn/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.rpm
как видим она отличается от:
wget --header 'Cookie: oraclelicense=accept-securebackup-cookie' https://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.rpm
тем что после download.oracle.com идёт otn поэтому добавляем otn-pub и всё теперь она будет работать.
всё, можно запускать роль:
ansible-playbook -u root /etc/ansible/playbooks/roles_play/activemq.yml --ask-pass