Hi,

I know the solution to this topic has been posted many times and I have 
tried searching through google and other forums including the ansible docs 
but unfortunately, nothing seems to be working for me. Please provide your 
feedback and help me with the solution. Also please let me know if you need 
any further information.

I am trying to create a playbook to download and install jenkins from a war 
file and so installing java from the source file as a pre-requisite.

I check for the presence of Java and if not found, go on to download and 
install java from source and then registering the env variable JAVA_HOME 
and adding the java binary onto my PATH. However, the environment variable 
part is frustratingly not working for me.

I initially started out with using the shell module to source /etc/profile 
using /bin/bash, but that didnt work. Read more and found out about 
environment keyword. As part of my playbook, I create a user jenkins_user 
and then download the jenkins war file and try to run with the above 
defined env variables.  unfortunately, it is not working. However, I am not 
sure I am doing this the correct way as I keep getting failures and the 
latest is that 'java' cannot be found by newly created jenkins_user.

Pasted below is all my code.

playbook.yaml


---
- hosts: all
  become: yes
  tasks:
    - name: Do I need to install java
      shell: java --version
      register: result
      ignore_errors: True


    - include: tasks/install_java.yaml
      when: result|failed



install_java.yaml



- name: Installing java and setting environment variables
      
  environment: 
    JAVA_HOME: /usr/share/jdk-9.0.4/
    PATH: $PATH:/usr/share/jdk-9.0.4/bin/


  get_url:
    url: https:
//download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz
    dest: /usr/share/
    owner: root
    group: root
    mode: 0644      
 
- name: unarchiving java source file
  unarchive:
    src: /usr/share/openjdk-9.0.4_linux-x64_bin.tar.gz
    dest: /usr/share/
    owner: root
    group: root
    mode: 0644


- name: changing permissions recursively
  file:
    path: /usr/share/jdk-9.0.4
    state: directory
    mode: 0755
    recurse: yes


- name: setting the environment
  blockinfile:
    backup: yes
    dest: /etc/profile.d/env.sh
    block: |
      JAVA_HOME=/usr/share/jdk-9.0.4/
      PATH=$PATH:/usr/share/jdk-9.0.4/bin/
    insertafter: EOF


    
- name: creating jenkins user
  
  user: 
    name: jenkinsuser
  register: creation


- include: tasks/install_jenkins.yaml
  when: creation|success

>
>
install_jenkins.yaml



 
- name: downloading latest jenkins war-stable
  get_url:
        url: http://mirrors.jenkins.io/war-stable/latest/jenkins.war
        dest: /home/jenkinsuser
        owner: jenkinsuser
        group: jenkinsuser
        mode: 0755


- name: starting jenkins war-stable
  shell: java -jar /home/jenkinsuser/jenkins.war
  args:
    executable: /bin/bash

>
>  

Thanks

Danish 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9e2565e2-a95b-4c10-970c-e632e86766e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to