1

I am trying to create a playboook that executes a python3 script with 2 parameters, name and password in localhost. However, when i try to execute the paybook with this command ansible -b --become-user=ras createdeploy.yaml --extra-vars "user=ras pass=ras" I get this error message:

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! Invalid variable name in vars specified for Play: 'pass' is not a valid variable name

The error appears to have been in '/home/ras/createdeploy.yaml': line 3, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  vars:
    user: "{{ user }}"
    ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

Here you are the .yaml file:

- hosts: all
  vars:
    user: "{{ user }}"
    pass: "{{ pass }}"

  tasks:
    - name: Stop services
      shell: "bash stopservices.sh"

    - name: Edit real hosts file
      shell: "bash editrealmachinehosts.sh"

    - name: Create dirs and cloning
      command: python3 user pass

1 Answer 1

3

I'd suggest that you first put some default values within the playbook (if you explicitly want your variables there, for the purpose of .. reducing interactivity/command line args lets say):

- hosts: all
  vars:
    user: greatuser
    passa: greatpassword

Second, I'm pretty sure that pass is a reserved word somewhere, although I'm failing to find it in the documentation. That's why I've changed your variable to passa. The final version of your playbook should look like this:

- hosts: all
  vars:
     user: greatuser
     passa: greatpassword

  tasks:
     - name: Stop services
       shell: "bash stopservices.sh"

     - name: Edit real hosts file
       shell: "bash editrealmachinehosts.sh"

     - name: Create dirs and cloning
       command: python3 {{ user }} {{ passa }}

Note the way used to reference to the username and password variables in the third task - {{ variable }} instead of variable.

Execute your playbook with the following command:

ansible-playbook createdeploy.yaml --extra-vars "user=ras passa=ras" -b --become-user=ras

As your target host is actually localhost (if I did understood you correctly), and since you're not showing your inventory file, I'd like to suggest that you might have to add -c local to the list of arguments of your ansible-playbook command.

1
  • 1
    pass is a reserved word in python
    – ras212
    Commented Aug 26, 2019 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.