Thanks Vino, i added to Json file as below, it runs successfully, but I 
don't understand command in yellow. Can you explain to me that command?

{
           "type": "shell",
            "execute_command": "echo '{{user `ssh_pass`}}' | {{ .Vars }} 
sudo -E -S sh '{{ .Path }}'",
            "inline": [
            "echo '%sudo    ALL=(ALL)  NOPASSWD:ALL' >> /etc/sudoers"]
           },
{
            "type": "ansible",
"playbook_file": "./create_image.yml"
       }
],
    
      "variables": {
       "ssh_pass": "shipped!!"
}

Vào 12:29:37 UTC+7 Thứ Hai, ngày 22 tháng 7 năm 2019, Vino Thiyagu đã viết:
>
> Make an entry for Sudo passwd in your ansible.cfg or keep your sudo passwd 
> in your Json as you kept for ssh pass
>
> On Mon, 22 Jul 2019 at 8:33 AM, Toan Huynh Van <[email protected] 
> <javascript:>> wrote:
>
>> Hi all, 
>>
>> I have a issue about sudo password when using packer to build image and 
>> Ansible for provisioning. The error as title. 
>>
>> below is my json file and playbook. Please help me resolve this issue. 
>>
>> packer.json
>>
>> {
>>     "builders": [
>>         {
>>             "type": "openstack",
>>               "identity_endpoint": "URL://",
>>               "tenant_name": "tenant",
>>               "username": "hvtoan",
>>               "password": "hvtoan",
>>               "availability_zone": "nova",
>>               "region": "RegionOne",
>>               "image_name": "Test_image_Packer",
>>               "source_image": "d3e5cbab-061d-4f7f-987d-c0d69b7e0bff",
>>               "ssh_username": "abc",
>>               "ssh_password": "xyz",
>>               "flavor": "m1.small",
>>               "security_groups": "default",
>>               "insecure": "true",
>>               "networks": [
>>                 "9b2bc188-4e27-4cdf-81ef-82287c3dce5c"
>>                 ]
>>         }
>>     ],
>>         "provisioners": [
>>         {
>>             "type": "ansible",
>>             "playbook_file": "./create_image.yml"
>>         }
>>     ]
>> }
>>
>> create_image.yml
>>
>> ---
>> - hosts: all
>>   gather_facts: no 
>>   ignore_errors: no
>>   become: yes
>>   become_method: sudo
>>   roles:
>>     - packer_test
>>
>> /etc/ansible/roles/packer_test/tasks/main.yml
>>
>> ---
>>  - name: create user
>>    become: yes
>>    become_method: sudo
>>    user:
>>      name: hvtoan
>>      comment: Huynh Toan
>>  - name: install apache2
>>    apt:
>>      name: httpd
>>      state: latest
>>      update_cache: yes
>>  - name: restart apache
>>    service:
>>      name: httpd
>>      state: restarted
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/f671b7f8-6225-4689-b9b5-4174687b8ec3%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/f671b7f8-6225-4689-b9b5-4174687b8ec3%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/728582df-f5d0-4fdc-975e-139812934978%40googlegroups.com.

Reply via email to