User Tools

Site Tools


ansible:ansible_cmd

This is an old revision of the document!


Ansible command examples

cmd

ansible all -m ping 
ansible foo.example.com -m yum -a "name=httpd state=installed"
ansible -i hosts all -m yum -a 'name=ncdu state=present'
ansible -i hosts all -m yum -a 'name=ncdu state=absent'
ansible foo.example.com -a "/usr/sbin/reboot"

Only way to pass a command on target without python installed

# ansible myhost --become -m raw -a "yum -y install python"
ansible-inventory --list
ansible-inventory -i ./sample.yml --graph
ansible-config dump --only-changed
ansible -m module_name -a attributes
ansible-config dump
ansible-config list
ansible-config view
# ansible all -m ping --one-line
lnx80 | SUCCESS => {"changed": false,"ping": "pong"}
lnx81 | SUCCESS => {"changed": false,"ping": "pong"}
aix01 | SUCCESS => {"changed": false,"ping": "pong"}
aix20 | SUCCESS => {"changed": false,"ping": "pong"}

playbook

# cat copy_file.yml
---
 - hosts: app
   tasks:
     - name: Fetch the file from the mwiapp01 to master
       run_once: yes
       fetch: src=/tmp/app01-to-app02.jar dest=buffer/ flat=yes
       when: "{{ inventory_hostname == 'mwiapp01' }}"

     - name: Copy the file from master to mwiapp02
       copy: src=buffer/app01-to-app02.jar dest=/tmp/
       when: "{{ inventory_hostname == 'mwiapp02' }}"
ansible/ansible_cmd.1636125200.txt.gz · Last modified: 2021/11/05 16:13 by manu