Score:0

Ansible - become: true - not becoming root on server

us flag

I am not sure if this is the right stackexchange site. Please let m know, if I should ask it on other forum and which one?

I need root access to perform an action, so I tried to use become: true

- name: Modify server.properties
  hosts: kafka_broker
  become: true

  vars:
    ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
    ansible_host_key_checking: false

  tasks:

    - name: I am confused
      command: 'whoami'
      register: myidentity

    - name: my secret identity
      debug:
        msg: "{{ myidentity.stdout }}"

    - name: "Add the line if it does not exist"
      become: true
      tags: addifnotexists
      lineinfile:
        path: /etc/kafka/server.properties
        line: "ssl.enabled.protocols = TLSv1.2"
        insertafter: EOF
        state: present
        backup: yes
      register: addifnotexists
    - debug: var=addifnotexists

One one set of servers, the user is actually root, on other set it is the account from which the script was executed.

    TASK [my secret identity] *********************************************************************************************************************************************
    ok: [server016] => {
        "msg": "svcacct"
    }
    ok: [server031] => {
        "msg": "svcacct"
    }
    ok: [server033] => {
        "msg": "svcacct"
    }

Other set of servers

    TASK [my secret identity] *********************************************************************************************************************************************
    ok: [server010] => {
        "msg": "root"
    }
    ok: [server011] => {
        "msg": "root"
    }
    ok: [server012] => {
        "msg": "root"
    }

Is this difference in the output due to any difference on the server set-up? What do I need to ask the systems admins to check or set-up

Thank you for any pointers you can provide

Michael Hampton avatar
cz flag
Check your host variable `become_user`.
adbdkb avatar
us flag
Thanks. On both sets of servers, in the /etc/ansible/ansible.cfg file, the line `become_user=root` exists, but on both it is prepended with `#`, so the line is `#become_user=root`. Where else can / should i check?
Michael Hampton avatar
cz flag
It could be set in a [wide variety of places](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#where-to-set-variables).
adbdkb avatar
us flag
Thanks. I will check. So, basically, I should find the become_user definition and correct it. I will look at the precedence too. Will ask if I need some guidance
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.