<p>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):</p>

<pre><code>- hosts: all
  vars:
    user: greatuser
    passa: greatpassword
</code></pre>

<p>Second, I'm pretty sure that <code>pass</code> is a reserved word somewhere, although I'm failing to find it in the <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html" rel="nofollow noreferrer">documentation</a>. That's why I've changed your variable to <code>passa</code>. The final version of your playbook should look like this:</p>

<pre><code>- 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 }}
</code></pre>

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

<p>Execute your playbook with the following command:</p>

<pre><code>ansible-playbook createdeploy.yaml --extra-vars "user=ras passa=ras" -b --become-user=ras
</code></pre>

<p>As your target host is actually <code>localhost</code> (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 <code>-c local</code> to the list of arguments of your <code>ansible-playbook</code> command. </p>

CC BY-SA 4.0
2019-08-26T12:21:10.383Z
pass is a reserved word in python
ras212
CC BY-SA 4.0
2019-08-26T12:17:24.440Z
2019-08-26T12:42:08.667Z
2019-08-26T12:42:08.667Z
13dimitar
<p>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 <code>ansible -b --become-user=ras createdeploy.yaml --extra-vars "user=ras pass=ras"</code> 
 I get this error message:</p>

<pre><code>[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 }}"
</code></pre>

<p>Here you are the .yaml file:</p>

<pre><code>- 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
</code></pre>

<ansible><configuration><yaml>
Error passing arguments to ansible playbook
ras212
# Error passing arguments to ansible playbook

(Asked by: username_0 on 2019-08-26)

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

**Tags:** ansible, configuration, yaml


---

## 1 answers

### Answer by username_1 on 2019-08-26. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: pass is a reserved word in python  

---

