Running the playbook below and wondering whats the correct syntax so I can use a variable within the find statement below
This line is in question -
when: p.stdout.find"{{(‘user’)}}" != -1
This would be correct without a variable
when: p.stdout.find(‘daniel’) != -1
How do I do this with a variable?
Playbook
- hosts: localhost
become: yes
vars:
user: daniel
tasks: - name: Create a new user on the server
user:
name: “{{user}}”
state: present - name: Check to ensure the user has been created
shell: cat /etc/passwd | grep “{{user}}”
register: p - debug: msg=“The user {{user}} exists”
when: p.stdout.find"{{(‘user’)}}" != -1 - name: Create a file in the /opt folder called program1.sh
command: touch program1.sh
args:
chdir: /opt
creates: program1.sh