vars:
mypassword: password
Consequently, the main.yml files does not contain anymore the vars directive.
- hosts: ssh
gather_facts: no
tasks:
- name: Update all packages
raw: apt-get update
- name: Install python
raw: apt-get install -y python python-apt
- name: Install openssh-server
apt: name=openssh-server state=present
- name: Create /var/run/sshd
file: path=/var/run/sshd state=directory owner=root group=root mode=0755
- name: Update sshd_config
replace: dest=/etc/ssh/sshd_config regexp='^PermitRootLogin without-password' replace='PermitRootLogin yes'
- name: Update pam settings
replace: dest=/etc/pam.d/sshd regexp='session\s*required\s*pam_loginuid.so' replace='session optional pam_loginuid.so'
- name: Update /etc/profile
lineinfile: dest=/etc/profile line='VISIBLE=now'
- name: Get encrypted password
shell: python -c 'import crypt; print crypt.crypt("{{ mypassword }}", "$1$SomeSalt$")'
register: output
- name: Set root password
user: name=root password="{{ output.stdout }}" update_password=always
$ ansible-container --var-file var_file.yml build
but it fails... because variables are not defined :
TASK [Get encrypted password] **************************************************
ansible-container_1 | fatal: [ssh]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'mypassword' is undefined\n\nThe error appears to have been in '/ansible-container/ansible/main.yml': line 18, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n lineinfile: dest=/etc/profile line='VISIBLE=now'\n - name: Get encrypted password\n ^ here\n"}
Thanks for your help.
Ernest.