ansible reboot 2.1.1.0 fails
I reboot servers with async
fire and forget mode:
- name: Restart server
become: yes
shell: sleep 2 && /sbin/shutdown -r now "Ansible system package upgraded"
async: 1
poll: 0
How to wait for server restart using Ansible?
You should change the wait_for task to run as local_action, and specify the host you're waiting for. For example:
- name: Wait for server to restart
local_action:
module: wait_for
host=192.168.50.4
port=22
delay=1
timeout=300
How can I use ansible playbook to reboot a ubuntu server?
Might I suggest to use a bridge or private network. Using the port forward might be tricky. I used your code with private and bridged network worked perfectly with both.
Every Ansible command responds with abort
I found the solution to my problem here. It's a problem with OpenSSL:
https://nbari.com/post/python-quit-unexpectedly-macos/
The steps to fix:
brew reinstall openssl
cd /usr/local/lib
sudo ln -s /usr/local/opt/openssl/lib/libssl.dylib libssl.dylib
sudo ln -s /usr/local/opt/openssl/lib/libcrypto.dylib libcrypto.dylib
ansible - cisco IOS and reload command
You can use:
- name: reload device
ios_command:
commands:
- "reload in 1\ny"
provider: "{{ cli }}"
This will reload the device in 1 minute and the reload prompt gets accepted. It works well for ansible because the default prompt of ios will come back (reload gets triggered in 1 minute).
Regards,
Simon
Ansible non-root sudo user and become privilege escalation
Why am I getting permission denied?
Because APT requires root permissions (see the error: are you root?
) and you are running the tasks as david
.
Per these settings:
become: true
become_user: david
become_method: sudo
Ansible becomes david
using sudo
method. It basically runs its Python script with sudo david
in front.
the user 'david' on the remote box has sudo privileges.
It means david
can execute commands (some or all) using sudo
-executable to change the effective user for the child process (the command). If no username is given, this process runs as the root
account.
Compare the results of these two commands:
$ sudo whoami
root
$ sudo david whoami
david
Back to the APT problem, you (from CLI) as well as Ansible (connecting with SSH using your account) need to run:
sudo apt-get install sqlite3
not:
sudo david apt-get install sqlite3
which will fail with the very exact message Ansible displayed.
The following playbook will escalate by default to the root user:
---
- name: Testing...
hosts: all
become: true
tasks:
- name: Just want to install sqlite3 for example...
apt: name=sqlite3 state=present
Check if Chocolatey is installed in Ansible
You can add a task to check choco
command is ready. And execute script InstallChocolatey.ps1
when choco
is not available.
---
- name: Check if Chocolatey is already installed
win_shell: (Get-Command choco).Path
register: get_command_choco
- name: Create C:\temp
win_file:
path: C:\temp
state: directory
- name: Save InstallChocolatey.ps1 file
template:
src: InstallChocolatey.ps1.j2
dest: c:\temp\InstallChocolatey.ps1
- name: Run InstallChocolatey.ps1
win_shell: C:\temp\InstallChocolatey.ps1
when: not get_command_choco.stderr == ""
Related Topics
Bash "&" Without Printing "[1]+ Done "
Authenticating Gtk App to Run with Root Permissions
Does Gcc Support Command Files
What's a Simple Method to Dump Pipe Input to a File? (Linux)
Virtually Contiguous VS. Physically Contiguous Memory
How to Disable Greeting Message When Ssh in to a Server
Cups Linux: Help Printing These Media Types: Ms Excel, Ms Word and HTML
How to Find The Version of a Compiled Kernel Module
Snort Message - Warning: No Preprocessors Configured for Policy 0
Scheduling in Linux: Run a Task When Computer Is Idle (= No User Input)
Apt-Update in Azure Nvidia Gives Publickey Error
Failed to Load Javahl Library.- Linux/Eclipse
Shell Script to Get List of Defined Users on Linux
The Only Overhead Incurred by Fork Is Page Table Duplication and Process Id Creation
Best Linux Filesystem Filter Option
Ffmpeg Install on Centos 64-Bit 'Install with -Fpic' Error