I am trying to install Java and set path by using Java tar file, I am getting error can anyone please suggest ASAP (Urgent)

22 views
Skip to first unread message

ashok kumar penumudi

unread,
Jan 21, 2019, 3:54:51 AM1/21/19
to Ansible Project
When i run below playbook getting error i am trying to set Java path. Please suggest ASAP

[cdhadmin@vboacisbs13 ansible]$ ansible-playbook java.yml --syntax -check
ERROR! Syntax Error while loading YAML.
  did not find expected key

The error appears to have been in '/etc/ansible/java.yml': line 12, column 6, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

     # lineinfile is used to add additional or append lines to existing files.
     - lineinfile :
     ^ here

[cdhadmin@vboacisbs13 ansible]$ sudo vi java.yml
---
- hosts: cloudera
  become: true
  tasks:
   - name: Download Java
     get_url: url=http://10.85.16.186/cm/cm5.14.2-centos7.tar.gz dest=/home/cdhadmin/Downloads
   - name: Extract & install Java
     command: tar zxvf /home/cdhadmin/Downloads/cm5.14.2-centos7.tar.gz -C /usr
   - name: Update Profile
     copy: content="export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk \n" dest=/etc/profile
     # lineinfile is used to add additional or append lines to existing files.
     - lineinfile :
       path: /etc/profile
       line: 'JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk'
       create: yes
   - name: Source profile
     shell: source /etc/profile.d

Dick Visser

unread,
Jan 21, 2019, 9:01:21 AM1/21/19
to ansible...@googlegroups.com
The indentation of your lineinfile task is off.
Also, to be consistent, you probably want to start that task by giving
it a "name:".

But once you've solved that, the rest of your playbook needs work, too.
Instead of having two command tasks (get_url + command), you should
use a single unarchive task.

A more serious problem is the last task (shell: source
/etc/profile.d). That does not do what you think it does.
Read https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html
for how to work with this
Each task has its own set of environment vars - they do not magically
carry over to subsequent tasks (which I suspect there are - the task
so far seems to just get and extract an archive).

Dick
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/32ee6a20-2f7c-4af0-9793-e542fbfd7636%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

goforawalktwice

unread,
Jan 21, 2019, 1:20:46 PM1/21/19
to Ansible Project
You also have a space between lineinfile and colon

ashok kumar penumudi

unread,
Jan 22, 2019, 7:21:12 AM1/22/19
to Ansible Project


---
- hosts: cloudera
  tasks:
     - name: Download Java
       get_url: url=http://10.85.16.186/cm/ansible-2.7.5.tar.gz dest=/home/cdhadmin/Downloads
     - name: Extract Java
       command: tar zxvf /home/cdhadmin/Downloads/ansible-2.7.5.tar.gz
     - name: set path for java file
       lineinfile:
        dest: /etc/environment
        state: present
        regexp: 'JAVA_HOME'
        line: 'JAVA_HOME: /usr/java/jdk1.8.0_171-amd64/'
        dest: /etc/environment
        state: present
        regexp: 'PATH'
        line: 'PATH=/usr/java/jdk1.8.0_171-amd64/bin:$PATH'
~

When i run above script 

the whole content is replacing by one line (PATH=/usr/java/jdk1.8.0_171-amd64/bin:$PATH')? could you please suggest how to append?

Reply all
Reply to author
Forward
0 new messages