Ansible: Can I execute role from command line?

前端 未结 7 852
陌清茗
陌清茗 2020-12-07 14:22

Suppose I have a role called \"apache\"

Now I want to execute that role on host 192.168.0.10 from the command line from Ansible host

ansible-playbook         


        
7条回答
  •  一个人的身影
    2020-12-07 14:59

    There is no such thing in Ansible, but if this is an often use case for you, try this script.
    Put it somewhere within your searchable PATH under name ansible-role:

    #!/bin/bash
    
    if [[ $# < 2 ]]; then
      cat <  [ansible-playbook options]
    
    Examples:
      $0 dest_host my_role
      $0 custom_host my_role -i 'custom_host,' -vv --check
    HELP
      exit
    fi
    
    HOST_PATTERN=$1
    shift
    ROLE=$1
    shift
    
    echo "Trying to apply role \"$ROLE\" to host/group \"$HOST_PATTERN\"..."
    
    export ANSIBLE_ROLES_PATH="$(pwd)/roles"
    export ANSIBLE_RETRY_FILES_ENABLED="False"
    ansible-playbook "$@" /dev/stdin <

提交回复
热议问题