FreeKB - ansible command - Getting Started
ansible command - Getting Started

Home > Search


This assumes you have installed Ansible Tower. The ansible command can can be used to perform a number of different tasks. By default, the ansible command is located at /usr/bin/ansible on Linux. For example, the -v or --version option can be used to list the version of Ansible, the location of the Ansible configuration file, and the version of Python. The ansible command is typically used for non-repetitive ad-hoc tasks. The ansible-playbook command is used for repetitive tasks, such as the installation and setup of software on a server.

ansible --version

ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/your_username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible playbook module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, mm dd yyyy, hh:mm:ss) [GCC 4.8.5 yyyymmdd (Red Hat 4.8.5-39)]

 

Let's say you want to ping target servers. First, you will need to create an inventory.yml file that contains the target hosts

all:
  children:
    windows:
      hosts:
        server1.example.com:
        server2.example.com:
    linux:
      hosts:
        server3.example.com:
        server4.example.com:

 

Now you can use the ansible command with the following options to ping each server in inventory.yml. 

  • all will perform the task against every server in inventory.yml, "windows" will perform the task against the Windows servers in inventory.yml, "linux" will perform the task against the Linux servers in inventory.yml.
  • -i inventory.yml or --inventory=inventory.yml or --inventory-file=inventory.yml
  • -m ping or --module-name=ping
     
ansible all -i inventory.yml -m pingĀ 

 

The following should be returned.

server1.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server2.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 3ca29 in the box below so that we can be sure you are a human.




Comments