[ansible] Some basic command line

For issuing commands to linux
ansible -m command -a "uname -a" localhost -u cyruslab -k

  • -m is the module
  • -a is the arguments, in this case we are issuing linux command uname -a
  • -u is the username
  • -k is ask for password
  • localhost is the ip address or hostname or the group name, the target device has to be included in the inventory file else ansible will reject even if the ip address/hostname exists

The result looks like this:
a1

Privilege escalation with ansible
a2
On this example, I want to use ansible to do this chmod 777 and also chown cyruslab:cyruslab /tmp/test.

ansible -m file -a "dest=/tmp/test mode=777 owner=cyruslab group=cyruslab" --become --become-method=sudo --become-user=root localhost -K

  • -m is the module, on file management the file module is used
  • -a is the argument, file module requires more arguments, mode is the file mode such as 777, 666, 644, 744, owner is the owner you want to change to, group is the group you want to change to.
  • --become is to indicate privilege escalation is required
  • --become-method is the method to escalate privilege, on linux it has sudo on cisco it has enable
  • --become-user is the privilege user you want to escalate to, on linux sudo is to become a root.
  • localhost, this can be hostname, ip address or a group specified within the inventory file
  • -K, not that this is a capital K which means ask for become password, in linux this is the sudo password.

a3
a4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s