Difference between revisions of "Ansible One-liners"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions 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=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 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/
 
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
 +
```

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