How to on ansible one liners?



  • The Options

    -i  - host inventory
    -m  - the ansible module
    -a  - the arguments
    

    Get the hostname using the shell module.

    $ ansible -i production all -m shell -a "hostname"
    

    Get the hostname and the redhat release.

    $ ansible -i production all -m shell -a "hostname;cat /etc/redhat-release" 
    

    Get a list of hosts the playbook will run against.

    $ ansible-playbook -i test site.yml --tags ntp --list-hosts
    playbook: site.yml
    
      play #1 (all): all    TAGS: []
        pattern: [u'all']
        hosts (24):
    ...
    ...
    

    Run playbook to execute roles, common, dbserver with elevated privs.

    $ ansible-playbook --sudo -i inventory/test playbooks/dbservers.yml  --ask-become-pass
    

    Use of variable on the command line specified in different way.

    $ ansible-playbook --sudo -i inventory/test playbooks/dbservers.yml  --ask-become-pass -e "httpd_port=8080"
    

Log in to reply
 

© Lightnetics 2024