0

I have a playbook which will checkout the code from git copy the changes to the respective remote server and execute the process and share the output back to github now that everything is fine lastly I need to restart the server,but my issue is it should not be root user how can I restart the server after executing the necessary changes with the user who is normal user access, server is weblogic,

---

- hosts: deploy
  tasks:

  - name: clone a private repository
    git:
      repo: 'git@172.28.xx.xx:Rakshith/BELLCANNADA.git'
      dest: /srvrs/osm104/PONG
      version: SAAS_1
      clone: yes

  - copy:
          src=/srvrs/osm104/PONG/COM/OSM/OPERATION/OSM_104/wlst1.properties
          dest=/srvrs/osm104/Oracle/Middleware/Oracle_Home/oracle_common/common/bin/wlst1.properties
          mode=0644
          backup=true
          remote_src=yes


  - name: Execute script
    shell: wlst.sh >> OUTPUT.txt
    args:
      chdir: /srvrs/osm104/Oracle/Middleware/Oracle_Home/oracle_common/common/bin/
      creates: OUTPUT.txt


  - copy:
          src=/srvrs/osm104/Oracle/Middleware/Oracle_Home/oracle_common/common/bin/OUTPUT.txt
          dest=/srvrs/osm104/PONG/COM/OSM/OPERATION/OSM_104/SAAS1.0_OUTPUT_EnvName.txt
          mode=0644
          backup=true
          remote_src=yes


 - name: Reboot server
   shell: reboot
    become: yes
    become_user: some_user
    local_action: wait_for host="{{ 10.36.xx.xx }}" search_regex=OpenSSH port=22 timeout=300
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Rakshu
  • 1
  • 4
  • It would be much easier if you just posted your playbook. – Gerald Schneider Aug 08 '17 at 13:46
  • I have placed now but its a user named osm104 not root so how to restart my weblogic server after the neccessary changes – Rakshu Aug 08 '17 at 13:54
  • 1
    I do not think it's possible to reboot a Linux system without privilage elevation. This means either root or someone that can act as root can reboot a Linux system (in usual scenario). This means your code `become_user: some_user` will prevent the reboot action from completing. If you have sudo enabled for reboot for that particular user try to call `shell: sudo reboot` instead. – Roman Spiak Nov 13 '21 at 14:27
  • Adding to the comment above by @RomanSpiak , how and with which user would you do the same thing manually (when you are connected with ssh to the same server)? If you know this then you can do the same things with ansible using `shell` and `become_user` – ttsakpc Aug 18 '22 at 10:05

1 Answers1

0

Maybe add a handler? You need to create a handles file under the roles directory. For example: roles/common/handlers/main.yml

- name: reboot server command: /sbin/reboot

Tux_DEV_NULL
  • 1,093
  • 7
  • 11