Difference between revisions of "Ansible One-liners"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
## Linux & Windows
 +
 +
use -e @vars/myfile.yaml for getting vars from file
 +
 
```
 
```
 
ansible all --inventory host.example.com, --module-name=win_shell --args='whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER -e ansible_winrm_transport=ntlm -e ansible_connection=winrm
 
ansible all --inventory host.example.com, --module-name=win_shell --args='whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER -e ansible_winrm_transport=ntlm -e ansible_connection=winrm
Line 5: Line 9:
 
```
 
```
  
# SUDO
+
## SUDO
 
```
 
```
 
ansible all --inventory host.example.com, --module-name=shell --args='sudo whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER  --become -e ansible_become_password=$ANSIBLE_PASSWORD
 
ansible all --inventory host.example.com, --module-name=shell --args='sudo whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER  --become -e ansible_become_password=$ANSIBLE_PASSWORD
Line 11: Line 15:
  
  
 
+
## Other
 
```
 
```
 
ansible 'Windows' -m win_shell -i inventory.txt -a 'cp C:\tmp\a.txt C:\tmp\b.txt'
 
ansible 'Windows' -m win_shell -i inventory.txt -a 'cp C:\tmp\a.txt C:\tmp\b.txt'

Latest revision as of 20:47, 29 November 2022

Linux & Windows

use -e @vars/myfile.yaml for getting vars from file

ansible all --inventory host.example.com, --module-name=win_shell --args='whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER -e ansible_winrm_transport=ntlm -e ansible_connection=winrm

ansible all --inventory host.example.com, --module-name=shell --args='whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER

SUDO

ansible all --inventory host.example.com, --module-name=shell --args='sudo whoami' -e ansible_password=$ANSIBLE_PASSWORD -e ansible_user=$ANSIBLE_USER  --become -e ansible_become_password=$ANSIBLE_PASSWORD

Other

ansible 'Windows' -m win_shell -i inventory.txt -a 'cp C:\tmp\a.txt C:\tmp\b.txt'

ansible 'Windows' -m copy -a "src=/tmp/foo.txt dest=/tmp/foo.txt" -i inventory.txt  # https://www.middlewareinventory.com/blog/ansible-copy-file-or-directory-local-to-remote/

Testing only - not recommended

export ANSIBLE_HOST_KEY_CHECKING=False