-1

I have a playbook like this, I tried to run it in ansible awx as job template but got an Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-tmp-1609214869.41401-6813-56941014390086/rhv-snapshots.py\", line 4, in <module>\n from prettytable import PrettyTable\nModuleNotFoundError: No module named 'prettytable' error, it works using ansible CLI but in awx didn't. any idea?

---
- hosts: localhost
  tasks:
    - name: "Creating Script..."
      copy:
        content: |
          #!/usr/bin/python3
          import xml.etree.ElementTree as ET
          from prettytable import PrettyTable
          
          print('hello world!')
        dest: /tmp/test.py
        mode: 777

    - name: "Running Script..."
      script: /tmp/test.py
      register: output

    - debug:
        var: output.stdout_lines
Levi
  • 64
  • 7

2 Answers2

0

You can create a file like files/test.py

And then you copy it:

copy:
  src: test.py
  dest: /tmp/test.py
  mode: '0777'
NRE
  • 604
  • 6
  • 14
  • I got this error ```ansible.errors.AnsibleFileNotFound: Could not find or access '/home/ec2-user/test2.py'````, it works with CLI – Levi Dec 29 '20 at 08:08
0

Can you check if your alignment is correct? The task name should come directly under tasks keyword. Please try the below code.

---
- hosts: localhost
  tasks:
  - name: "Creating Script..."
    copy:
      content: |
        #!/usr/bin/python3
        import xml.etree.ElementTree as ET
        from prettytable import PrettyTable
        print('hello world!')
      dest: /tmp/test.py
      mode: 777

  - name: "Running Script..."
    script: /tmp/test.py
    register: output
  - debug:
     var: output.stdout_lines
Smily
  • 2,308
  • 2
  • 17
  • 41