action-ansible-playbook icon indicating copy to clipboard operation
action-ansible-playbook copied to clipboard

Install dependency before Ansible runs on GitHub runner

Open mjovanc opened this issue 1 year ago • 2 comments

Perhaps this is not the right community. But I'm using your plugin in my pipeline and I need to somehow install the dependency before even running Ansible on the Github Runner. And that does not seem to work for some reason. Any idea what this could be?

deploy:
    name: Deploy
    runs-on: ubuntu-latest
    needs: build-docker

    steps:
    - name: Check out the codebase.
      uses: actions/checkout@v2

    - name: Uses Python 3.11
      uses: actions/setup-python@v3
      with:
        python-version: '3.11.0-alpha.1'

    - name: Install Jmespath Dependency
      run: |
        pip3 install jmespath
        pip3 freeze # just to see what is installed
        sudo apt install -y python3-jmespath

    - name: Run playbook
      uses: dawidd6/action-ansible-playbook@v2
      with:
        playbook: provision_vps.yml
        directory: ./ansible
        key: ${{secrets.ANSIBLE_PRIVATE_KEY}}
        vault_password: ${{secrets.ANSIBLE_VAULT_PASS}}
        options: |
          --inventory hosts.inventory
          --verbose

The error message I get is:

fatal: [cache.hugin.chat]: FAILED! => {"msg": "You need to install \"jmespath\" prior to running json_query filter"}

mjovanc avatar Jul 19 '22 15:07 mjovanc

Look where Ansible is installed on the runner. I'm guessing it's going to be somewhere inside /opt. Then try to pinpoint the Python interpreter that Ansible uses to run and run this Python's pip to install the module.

dawidd6 avatar Jul 19 '22 18:07 dawidd6

Try it. ansible --version will show you where is the ansible installed. It's installed by pipx.

    - name: Setup ansible
      run: |
        ansible --version
        pipx inject ansible-core jmespath

cupen avatar Sep 01 '22 03:09 cupen