Score:0

Ansible error getting again and again

sc flag

ERROR! conflicting action statements: hosts, tasks

The error appears to be in '/home/a899444/aerospike-ansible/roles/java_install/tasks/main.yml': line 1, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Java installation
 ^ here
- name: Java installation
  hosts: remote_server
  become: true
  tasks:
    - name: Download the JDK binaries
      get_url:
        url: https://download.java.net/java/GA/jdk18.0.2.1/db379da656dc47308e138f21b33976fa/1/GPL/openjdk-18.0.2.1_linux-x64_bin.tar.gz
        dest: /opt/openjdk-18.0.2.1_linux-x64_bin.tar.gz

    - name: Unzip the downloaded file
      unarchive:
        src: /opt/openjdk-18.0.2.1_linux-x64_bin.tar.gz
        dest: /opt
        remote_src: yes

    - name: Set the JAVA_HOME in /etc/profile file
      lineinfile:
        path: /etc/profile
        state: present
        line: "{{ item }}"
      with_items:
        - 'export JAVA_HOME="/opt/jdk-18.0.2.1"'
        - 'export PATH=$PATH:$JAVA_HOME/bin'

    - name: Reload /etc/profile file
      shell:
        cmd: source /etc/profile
Score:0
in flag

In a role the tasks file can only contain tasks, yet you use the format of a playbook. Remove the hosts and everything else from the top level:

- name: Download the JDK binaries
  get_url:
    url: https://download.java.net/java/GA/jdk18.0.2.1/db379da656dc47308e138f21b33976fa/1/GPL/openjdk-18.0.2.1_linux-x64_bin.tar.gz
    dest: /opt/openjdk-18.0.2.1_linux-x64_bin.tar.gz

- name: Unzip the downloaded file
  unarchive:
    src: /opt/openjdk-18.0.2.1_linux-x64_bin.tar.gz
    dest: /opt
    remote_src: yes

- name: Set the JAVA_HOME in /etc/profile file
  lineinfile:
    path: /etc/profile
    state: present
    line: "{{ item }}"
  with_items:
    - 'export JAVA_HOME="/opt/jdk-18.0.2.1"'
    - 'export PATH=$PATH:$JAVA_HOME/bin'

- name: Reload /etc/profile file
  shell:
    cmd: source /etc/profile

The hosts definition belongs in the playbook where you use the role:

hosts: remote_server
become: true
roles:
  - java_install

You might want to use some variables instead of fixed paths and filenames though. And that last task is completely useless. Every task starts a new shell where that file is read anyway.

And the unarchive module accepts URLs. You can reduce that to two tasks:

- name: Unzip JDK
  unarchive:
    src: https://download.java.net/java/GA/jdk18.0.2.1/db379da656dc47308e138f21b33976fa/1/GPL/openjdk-18.0.2.1_linux-x64_bin.tar.gz
    dest: /opt

- name: Set the JAVA_HOME in /etc/profile file
  lineinfile:
    path: /etc/profile
    state: present
    line: "{{ item }}"
  with_items:
    - 'export JAVA_HOME="/opt/jdk-18.0.2.1"'
    - 'export PATH=$PATH:$JAVA_HOME/bin'
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.