dawidd6 / action-ansible-playbook

:gear: A GitHub Action for running Ansible playbooks
MIT License
306 stars 68 forks source link

Install dependency before Ansible runs on GitHub runner #52

Closed mjovanc closed 2 years ago

mjovanc commented 2 years ago

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"}
dawidd6 commented 2 years ago

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.

cupen commented 2 years ago

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