Cheatography
                https://cheatography.com
            
        
        
    
                   
                            
    
                    Quick and fast reminder for Ansible command line
                    
                 
                    
        
        
            
    
        
                                    This is a draft cheat sheet. It is a work in progress and is not finished yet.
                    
        
                
        
            
                                
            
                
                                                
                                
    
    
            ansible-playbook
        
                        
                                                                                    
                                                                                            <YAML>  | 
                                                                                                                        Run on all hosts defined  | 
                                                                                 
                                                                                            
                                                                                            <YAML> -f 10  | 
                                                                                                                        Run 10 hosts in parallel  | 
                                                                                 
                                                                                            
                                                                                            <YAML> -v  | 
                                                                                                                        Verbosity (-vv, -vvv)  | 
                                                                                 
                                                                                            
                                                                                            <YAML> -C -D  | 
                                                                                                                        -C: Dry run    -D: Diff  | 
                                                                                 
                                                                                            
                                                                                            <YAML> -l <host>  | 
                                                                                                                        Run the playbook against <host>  | 
                                                                                 
                                                                                            
                                                                                            <YAML> [--list-hosts | --list-tasks]  | 
                                                                                                                        Show [hosts | tasks] triggered for each play  | 
                                                                                 
                                                                                            
                                                                                            <YAML> --syntax-check  | 
                                                                                                                        Self explanatory  | 
                                                                                 
                                                                                            
                                                                                            <YAML> --start-at-task "my task"  | 
                                                                                                                        Start PB at specific task  | 
                                                                                 
                                                                                            
                                                                                            <YAML> --tags "tag1,tag2"  | 
                                                                                                                        Only run tasks with tag1 and 2  | 
                                                                                 
                                                                                            
                                                                                            <YAML> --tags [tag1,tag2]  | 
                                                                                                                        Only run tasks with tag1 or 2  | 
                                                                                 
                                                                                            
                                                                                            <YAML> --skip-tags [tag1,tag2]  | 
                                                                                                                        Skip tasks with tag1 or 2  | 
                                                                                 
                                                                                            
                                                                                            <YAML> -e "APP_USER=john"  | 
                                                                                                                        Override variable in your playbook  | 
                                                                                 
                                                                                            
                                                                                            --become --become-method=doas --become-user=www-data --ask-become-pass  | 
                                                                                                                        Run the playbook as www-data. Use method runas for windows hosts  | 
                                                                                 
                                                                                            
                                                                                            ... --ask-vault-pass  | 
                                                                                                                        Ask for the vault pass at runtime  | 
                                                                                 
                                                                                            
                                                                                            ... --vault-password-file <vault_password_file>  | 
                                                                                                                        If you vault pass is in a file  | 
                                                                                 
                                                                                            
                                                                                            <YAML> [-C | --check]  | 
                                                                                                                        Dry run  | 
                                                                                 
                                                                         
                             
                             | 
                                                                              | 
                                                        
                                
    
    
            Ansible-galaxy
        
                        
                                                                                    
                                                                                            [collection | role] list  | 
                                                                                                                        List installed collections or roles  | 
                                                                                 
                                                                                            
                                                                                            install <galaxy.repo> -p ./roles  | 
                                                                                                                        Install the role into ./roles/galaxy.repo folder  | 
                                                                                 
                                                                         
                             
    
    
            ansible
        
                        
                                                                                    
                                                                                            all -m ping  | 
                                                                                                                        Check if hosts are reachable  | 
                                                                                 
                                                                                            
                                                                                            <HOST> -m setup  | 
                                                                                                                        Gather facts for <HOST>  | 
                                                                                 
                                                                                            
                                                                                            <HOST> -m setup --tree /tmp/file  | 
                                                                                                                        Save facts in </tmp/file>  | 
                                                                                 
                                                                                            
                                                                                            all -m setup -a 'filter=ansible_distribution*'  | 
                                                                                                                        Get only specific facts on all hosts  | 
                                                                                 
                                                                                            
                                                                                            <GROUP> -a "ip a"  | 
                                                                                                                        Exec arbitrary cmd on hosts  | 
                                                                                 
                                                                         
                             
    
    
            Ansible-vault
        
                        
                                                                                    
                                                                                            create <fileName>  | 
                                                                                 
                                                                                            
                                                                                            edit <fileName>  | 
                                                                                                                        Will ask you for the password when editor open and encrypt the file back when you exit editor  | 
                                                                                 
                                                                                            
                                                                                            decrypt <fileName>  | 
                                                                                 
                                                                                            
                                                                                            encrypt <fileName>  | 
                                                                                 
                                                                                            
                                                                                            view  <fileName>  | 
                                                                                 
                                                                         
                             
    
    
            ansible-config
        
                        
                                                                                    
                                                                                            list  | 
                                                                                                                        List all possible configurations  | 
                                                                                 
                                                                                            
                                                                                            view  | 
                                                                                                                        Show current config  | 
                                                                                 
                                                                                            
                                                                                            dump  | 
                                                                                                                        Display all current config value and where it is set  | 
                                                                                 
                                                                         
                             
                             | 
                                                                              | 
                                                        
                                
    
    
            ansible-inventory [-i INVENTORY]
        
                        
                                                                                    
                                                                                            --graph  | 
                                                                                                                        Show inventory graph  | 
                                                                                 
                                                                                            
                                                                                            --list  | 
                                                                                                                        Display hosts info  | 
                                                                                 
                                                                                            
                                                                                            --host <HOST>  | 
                                                                                                                        Display host info  | 
                                                                                 
                                                                                            
                                                                                            -i [INVENTORY] -y  | 
                                                                                                                        Display inventory with processed variables  | 
                                                                                 
                                                                         
                             
                             |