Software >> Automation >> Ansible >>  Ansible cheat sheet

Jump to: Shell |

 

 

copy

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html


## PLAYBOOK

copy1.yml
---
- name: Copy module - example 1
  hosts: all
  become: True
  vars:
    srcfile: "myscript.sh"
    srcdir: "/home/ansible"
    destdir: "/home/ansible"
    owner: "ansible"
    group: "ansible"
    perm: "0755"

  tasks:
  - name: Copy file and set ownership and permissions
    copy:
       src: "{{ srcdir }}/{{ srcfile }}"
       dest: "{{ destdir }}"
       owner: "{{ owner }}"
       group: "{{ group }}"
       mode: "{{ perm }}"

  - name: Verify file was copied
    shell: "ls -ldh {{ destdir }}/{{ srcfile }}"
    register: listing
  - debug: msg="{{ listing.stdout }}"



## OUTPUT


 
 

 

 

fetch

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/fetch_module.html

 
 

 

 

service

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html

 
 

 

 

shell

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/shell_module.html


## PLAYBOOK

shell1.yml

---
- name: ansible shell module - example 1
  hosts: all
  become: True
  tasks:

  - name: Show uptime
    shell: uptime
    register: results1
  - debug: msg="{{ results1.stdout_lines }}"



## OUTPUT




 

 

Yum

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html

playbook :


output :





 

 

 

playbook :


output :





 

 

 

playbook :


output :





 

 

 

playbook :


output :





 

 

 

playbook :


output :





 

 

 

playbook :


output :





 

 

 

playbook :


output :





 

References

  1. ansible.builtin plugins and modules index
  2. ansible collections index
  3. ansible loops
  4. ansible conditionals
  5. ansible playbook error handling
  6. ansible playbook tests
  7. ansible playbook blocks
  8. ansible playbook roles
  9. ansible playbook files